将一些Jquery代码转换为Mootools

时间:2012-03-11 20:18:40

标签: javascript jquery mootools

该代码用于google maps api以自动填充搜索地址。我必须转换它,因为我的joomla网站发生冲突。我如何用Mootools 1.4实现同样的目标?一些帮助将不胜感激!

以下是代码:

$(document).ready(function() { 

  initialize();

  $(function() {
    $("#entry_3").autocomplete({
      //This bit uses the geocoder to fetch address values
      source: function(request, response) {
        geocoder.geocode( {'address': request.term }, function(results, status) {
          response($.map(results, function(item) {
            return {
              label:  item.formatted_address,
              value: item.formatted_address,
              latitude: item.geometry.location.lat(),
              longitude: item.geometry.location.lng()
            }
          }));
        })
      },
      //This bit is executed upon selection of an address
      select: function(event, ui) {
        $("#entry_4").val(ui.item.latitude);
        $("#entry_5").val(ui.item.longitude);
        var location = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
        marker.setPosition(location);
        map.setCenter(location);
      }
    });
  });
});

修改: 添加window.onunload = GUnload是错误的;在谷歌地图api v3。这是一个v2功能。 v3不需要onunload。这搞砸了自动完成功能。

1 个答案:

答案 0 :(得分:0)

你不需要在mootools中编写代码 jquery没有冲突

jQuery.noConflict();
     jQuery(document).ready(function($){
       // you're jquery code

     });

http://docs.jquery.com/Using_jQuery_with_Other_Libraries