[英]jQuery conflict
我的页面上有一个wordpress插件lightbox2和一个新闻滚动条。
我的头部看起来像这样
<script type="text/javascript" src="wp-content/themes/soundsright/menu.js"></script>
<script type='text/javascript' src='wp-includes/js/prototype.js?ver=1.6'></script>
<script type='text/javascript' src='wp-includes/js/scriptaculous/wp-scriptaculous.js?ver=1.8.0'></script>
<script type='text/javascript' src='wp-includes/js/scriptaculous/effects.js?ver=1.8.0'></script>
<script type='text/javascript' src='wp-content/plugins/lightbox-2/lightbox.js?ver=1.8'></script>
<script type='text/javascript' src='wp-includes/js/jquery/jquery.js?ver=1.3.2'></script>
<!-- begin lightbox scripts -->
<script type="text/javascript">
//<![CDATA[
document.write('<link rel="stylesheet" href="wp-content/plugins/lightbox-2/Themes/Grey/lightbox.css" type="text/css" media="screen" />');
//]]>
</script>
<!-- end lightbox scripts -->
<!-- SwfObj Plugin version SWFOBJ_VERSION -->
<script type="text/javascript" src="wp-content/plugins/swfobj/swfobject.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="wp-content/themes/soundsright/liscroll.js"></script>
<script type="text/javascript">
$(function(){
$("ul#ticker01").liScroll({travelocity: 0.03});
});
</script>
到目前为止,新闻滚动条有效,但灯箱插件无效。 当我删除
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
则灯箱有效,但新闻滚动条无效。
我认为删除此jQuery引用将解决此问题,因为wordpress已在此行中加载了相同版本的jQuery
<script type='text/javascript' src='wp-includes/js/jquery/jquery.js?ver=1.3.2'></script>
有任何想法我在这里做错了吗?
我认为这是由于function()
冲突造成的,我们最近有类似的事情。 您需要更精确地将其与jQuery匹配(基本上$引用将由原型或其他JavaScript之一拥有,因此您将其替换为jQuery)例如
jQuery(function(){
jQuery("ul#ticker01").liScroll({travelocity: 0.03});
});
Prototype和jQuery都使用$:
由于JQuery和Prototype都使用$符号,因此请在非冲突模式下使用Jquery
jQuery.noConflict();
JQuery(function(){
JQuery("ul#ticker01").liScroll({travelocity: 0.03});
});
并使用$作为原型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.