2010-06-03 59 views
-2
<script type="text/javascript" src="jquery-1.js"></script> 
<script type="text/javascript" src="mootools.js"></script> 
<script type="text/javascript" src="slideshow.js"></script> 
<script type="text/javascript"> 
//<![CDATA[ 
    window.addEvent('domready', function(){ 
    var data = { 
     '1.jpg': { caption: 'Volcano Asención in Ometepe, Nicaragua.' }, 
     '2.jpg': { caption: 'A Ceibu tree.' }, 
     '3.jpg': { caption: 'The view from Volcano Maderas.' }, 
     '4.jpg': { caption: 'Beer and ice cream.' } 
    }; 
    var myShow = new Slideshow('show', data, {controller: true, height: 400, hu: 'images/', thumbnails: true, width: 500}); 
    }); 
//]]> 
</script> 
<script type="text/javascript"> 
$(document).ready(function() 
{ 
//slides the element with class "menu_body" when paragraph with class "menu_head" is clicked 
$("#firstpane p.menu_head").click(function() 
    { 
    $(this).css({backgroundImage:"url(down.png)"}).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow"); 
     $(this).siblings().css({backgroundImage:"url(left.png)"}); 
}); 
//slides the element with class "menu_body" when mouse is over the paragraph 
$("#secondpane p.menu_head").mouseover(function() 
    { 
     $(this).css({backgroundImage:"url(down.png)"}).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow"); 
     $(this).siblings().css({backgroundImage:"url(left.png)"}); 
}); 
}); 
</script> 

<!--[if lt IE 7]> 
     <script type="text/javascript" src="unitpngfix.js"></script> 
<![endif]--> 
+3

那麼究竟是什麼問題呢?什麼樣的衝突? – Marc 2010-06-03 21:03:37

回答

2

在包含jQuery之後,您應該調用$ .noConflict()。這將刪除從全局命名空間中的「$」:

<script type="text/javascript" src="jquery-1.js"></script> 
<script> 
$.noConflict(); 
</script> 
<script type="text/javascript" src="mootools.js"></script> 

在這一點上,你應該使用jQuery的代替$,如果你想調用jQuery代碼。或者你可以通過在封閉包裹$符號使用

<script type="text/javascript"> 
jQuery(function($) { 
    // here you can use $ instead of jQuery 
}); 
</script> 
3

jQuery的無衝突是一個不錯的選擇。我建議儘管做這樣的事情:

<script language=javascript> 
    var $j = jQuery.noConflict(); 
</script> 

這將讓您訪問jQuery的功能使用$ j代替$。我使用這種方法通過GreaseMonkey在大多數頁面中包含jQuery。我有一個jQuery的自定義副本,最後包含上面的調用。我使用GreaseMonkey將一個指向該腳本的鏈接插入到網頁頭部,以便我可以使用$ j調查對象屬性,而不會影響頁面中可能存在的其他庫並使用$。