[英]jQuery conflict
I have a wordpress plugin lightbox2 and a news scroller on my page. 我的页面上有一个wordpress插件lightbox2和一个新闻滚动条。
My head section looks like this 我的头部看起来像这样
<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>
As it is now, the news scroller works but not the lightbox plugin. 到目前为止,新闻滚动条有效,但灯箱插件无效。 When I remove
当我删除
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
then the lightbox works but not the news scroller. 则灯箱有效,但新闻滚动条无效。
I thought removing this jQuery refrence would have solved the problem cause wordpress already loads the same version of jQuery in this line 我认为删除此jQuery引用将解决此问题,因为wordpress已在此行中加载了相同版本的jQuery
<script type='text/javascript' src='wp-includes/js/jquery/jquery.js?ver=1.3.2'></script>
Any ideas what I'm doing wrong here? 有任何想法我在这里做错了吗?
I think this will be because of the function()
clashing, we had something similar recently; 我认为这是由于
function()
冲突造成的,我们最近有类似的事情。 you need to more precisely match it to jQuery (basically the $ reference will be owned by prototype or one of the other javascripts so you replace it with jQuery) eg 您需要更精确地将其与jQuery匹配(基本上$引用将由原型或其他JavaScript之一拥有,因此您将其替换为jQuery)例如
jQuery(function(){
jQuery("ul#ticker01").liScroll({travelocity: 0.03});
});
$ is used by both Prototype and jQuery: Prototype和jQuery都使用$:
http://docs.jquery.com/Using_jQuery_with_Other_Libraries http://docs.jquery.com/Using_jQuery_with_Other_Libraries
Since both JQuery and Prototype use $ sign, use Jquery in non conflict mode 由于JQuery和Prototype都使用$符号,因此请在非冲突模式下使用Jquery
jQuery.noConflict();
JQuery(function(){
JQuery("ul#ticker01").liScroll({travelocity: 0.03});
});
and use $ for Prototype 并使用$作为原型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.