2010-08-06 102 views
3

我的项目中有多个jquery文件。我使用的是使用jquery1.4.2的facebox,但我也需要prototype和scriptacolous脚本。我已经使用jQuery.noconflict();在我的代码,但它不工作。 这是网址http://mlep.com/~avalon/wordpress/ideas-and-insights/case-studies/解决多个jQuery文件之间的冲突

+1

你应该考虑从首页删除一些不使用的脚本文件,你的资源堆起来几乎1MB,这将在一个较慢的连接上花费一生的时间。只需要在需要它们的页面上使用插件,就可以提供更好的用户体验。 – Marko 2010-08-06 02:16:06

回答

0

它应该是在装置的这种方式,

  1. 负载其他库和其他非jQuery的脚本
  2. 负载jQuery库。
  3. 调用jQuery.noConflict。
  4. 负荷的jQuery插件
  5. 其他jQuery的东西或代码..

代码这样,

<script type="text/javascript" src="http://mlep.com/~avalon/wordpress/wp-content/themes/twentyten/facebox/jquery14.js"></script> 
<script type="text/javascript"> 
    var ang = jQuery.noConflict(); 
</script> 
<script type="text/javascript" src="http://mlep.com/~avalon/wordpress/wp-content/themes/twentyten/facebox/facebox.js"></script> 
<script type="text/javascript"> 
    // other jQuery Codes here... 
</script> 
+0

现在,不用'('stuff')。whatever()',你需要使用ang('stuff')。whatever()'。当我在非冲突模式下使用jQuery时,我通常使用'$ j',因为它很短并接近正常的jQuery函数。 – 2010-08-06 02:13:50

+0

从源代码判断,也正在使用'jQuery()'&'ang()'引用的混合,这可能会让人感到困惑。会推荐使用其中一种。 – Ross 2010-08-06 02:17:41

+0

谢谢我只是按照您的指示更改了序列,现在它工作正常。 – Amol 2010-08-06 04:54:04