冲突:加载子页时,JavaScript不起作用



我正在尝试将这个特定的应用程序集成到我的网站中。

当我将其作为内容加载到主页时,主页上的jquery菜单将停止工作。这里似乎有冲突。以下是子页面中的脚本:

<script type='text/javascript'>
  $(function() {
    var bucharest = new google.maps.LatLng(44.436055, 26.097593),
      pointToMoveTo, 
      first = true,
      curMarker = new google.maps.Marker({}),
      $el;
  var myOptions = {
      zoom: 13,
      center: bucharest,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
  var map = new google.maps.Map($("#map_canvas")[0], myOptions);
  $("#locations li").mouseenter(function() {
    $el = $(this);
    if (!$el.hasClass("hover")) {
      $("#locations li").removeClass("hover");
      $el.addClass("hover");
      if (!first) { 
        // Clear current marker
        curMarker.setMap(); 
        // Set zoom back to Bucharest level
        // map.setZoom(10);
      }
      // Move (pan) map to new location
      pointToMoveTo = new google.maps.LatLng($el.attr("data-geo-lat"), $el.attr("data-geo-long"));
      map.panTo(pointToMoveTo);
      // Add new marker
      curMarker = new google.maps.Marker({
          position: pointToMoveTo,
          map: map,
          icon: "images/marker.png"
      });
      // On click, zoom map
      google.maps.event.addListener(curMarker, 'click', function() {
         map.setZoom(14);
      });
      // Fill more info area
      $("#more-info")
        .find("h2")
          .html($el.find("h3").html())
          .end()
        .find("p")
          .html($el.find(".longdesc").html());
      // No longer the first time through (re: marker clearing)        
      first = false; 
    }
  });
  $("#locations li:first").trigger("mouseenter");
});

这是主页中菜单的脚本:

$(document).ready(function() {
    $("ul#nav li a").addClass("js");
    $("ul#nav li a").hover(
      function () {
        $(this).stop(true,true).animate({backgroundPosition:"(0 0)"}, 200);
        $(this).animate({backgroundPosition:"(0 -5px)"}, 150);
      },
      function () {
        $(this).animate({backgroundPosition:"(0 -149px)"}, 200);
      }
    );
});

这两者之间有冲突吗?非常感谢。

我认为您的第一份文档中有一个错误。准备

here : $(function() {

所以第二份文件。准备

this one : $(document).ready(function() {

最新更新