2010-01-15 38 views
2

我正在使用JQuery的一些下拉导航功能。工作很好。现在我只是添加了Cycle JQuery Plugin,我只能得到一个工作,具体取决于我在头部列出他们的顺序。我已阅读关于jQuery.noConflict();功能,但并不确定把它放在哪里。这是我得到的。jQuery的冲突 - 如何使用jQuery.noConflict();

HTML

<head> 
    <title>#</title> 

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/> 
    <meta content="online restaurant employee scheduling, employee scheduling, scheduling software, employee scheduling software, restaurant scheduling, restaurant scheduling software, restaurant schedules, restaurant employee scheduling, online scheduling, online scheduling software" name="keywords"/> 
    <meta content=" easy-to-use, Web-based restaurant labor management solutions and workforce management software offers flexible, effective and improved communication for employees and managers." name="description"/> 
    <meta content="index, follow" name="robots"/> 
    <meta content="no-cache" http-equiv="cache-control"/> 
    <meta content="no-store" http-equiv="cache-control"/> 
    <meta content="0" http-equiv="expires"/> 
    <meta content="no-cache" http-equiv="pragma"/> 
    <meta content="Rh52pxT6lFEqOVMlSt7QpOVHb325OHdlGkWZ0QMUSbU" name="google-site-verification"/> 

    <link rel="stylesheet" href="stylesheets/style.css" media="screen" /> 

    <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script> 
    <script src="js/jquery.cycle.all.min.js" type="text/javascript"></script> 
    <script src="js/menu.js" type="text/javascript"></script> 
    <script src="js/slideshow.js" type="text/javascript"></script> 

</head> 

当它的结构是这样我Cycle插件作品,但不是导航下拉菜单。下面是相应的.js与资产净值存在文件:menu.js和Cycle插件的存在:slideshow.js

menu.js

$(document).ready(function() { 

    $('#nav li').hover( 
     function() { 
      //show its submenu 
      $('ul', this).slideDown(100); 
     }, 
     function() { 
      //hide its submenu 
      $('ul', this).slideUp(100);   
     } 
    ); 

}); 

slideshow.js

$('#slideshow').cycle({ 
    speed:  200, 
    timeout: 0, 
    pager:  '#tabs', 
    pagerEvent: 'mouseover' 
}); 
+1

那是slideshow.js的全部内容?如果是这样,你可能希望在加载页面之后运行它,比如menu.js。 – 2010-01-15 05:43:01

回答

1

我看不出为什么你需要jQuery.noConflict()这是与其他脚本使用$变量。请参阅documentation

相反,莱恩说,你需要放置一个$(document).ready()内的循环代码,所以slideshow.js变成:

$(document).ready(function() { 
    $('#slideshow').cycle({ 
     speed:  200, 
     timeout: 0, 
     pager:  '#tabs', 
     pagerEvent: 'mouseover' 
    }); 
}); 
+0

所以我做到了这一点,仍然没有。我现在已经有了slideshow.js,但是只有幻灯片放映不在菜单中。你会在头上列出哪些脚本? – bgadoci 2010-01-15 14:51:44

+0

它应该没有什么区别它们列出的顺序。尝试构建一个最小的测试页面。 – 2010-01-15 16:31:06

2

documentation of noConflict()

注:此功能必须调用 船尾呃包括了jQuery JavaScript的 文件,但包括任何其他 冲突的库,而且实际上是相互冲突 库被使用之前 ,以防jQuery是 最后列入前。在jQuery.js 文件末尾调用noConflict可以调用 以全局禁用$() jQuery别名。

只是一个脚本标记添加到您的标题后,您的jQuery包含运行noConflict()函数(例如,从 “Using jQuery with noConflict” 页面获取):

<head> 
    <script src="prototype.js"></script> 
    <script src="jquery.js"></script> 
    <script> 
    jQuery.noConflict(); 

    // Use jQuery via jQuery(...) 
    jQuery(document).ready(function(){ 
     jQuery("div").hide(); 
    }); 

    // Use Prototype with $(...), etc. 
    $('someid').hide(); 
    </script> 
</head> 
0
<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script> 
<script>jQuery.noConflict();</script> 
<script src="js/jquery.cycle.all.min.js" type="text/javascript"></script> 
<script src="js/menu.js" type="text/javascript"></script> 
<script src="js/slideshow.js" type="text/javascript"></script> 

menu.js:

(function($){ 
$(document).ready(function() { 

    $('#nav li').hover( 
     function() { 
      //show its submenu 
      $('ul', this).slideDown(100); 
     }, 
     function() { 
      //hide its submenu 
      $('ul', this).slideUp(100);   
     } 
    ); 

}); 
})(jQuery); 

slideshow.js:

(function($){ 

$('blah').cycle() 
})(jQuery); 
+0

感谢您的回答。我按照说明和相同的结果做了这个。幻灯片的作品,但不是菜单不。我假设'等等'只是因为我应该在你的答案中理解这一点,但只是想确认一下。我可能做错了什么? – bgadoci 2010-01-15 05:07:03

+0

如果您有与noConflict业务完全不同的问题,您可以提出一个单独的问题吗?并提供HTML? – 2010-01-15 05:21:35

+0

我试过一样,但只有一个作品... – piku 2010-05-15 11:42:54