[英]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.