2009-06-17 102 views
0

我在網站上使用原型+ jQuery。現在原型插件使用$。我不希望jQuery使用$。我如何讓jQuery不註冊$。另外,我該如何調用jQuery函數。

謝謝你的時間。

回答

16

jQuery documentation有一篇關於如何讓jQuery和其他庫很好的文章。

這是那篇文章提出的一種方式:

<html> 
<head> 
    <script src="prototype.js"></script> 
    <script src="jquery.js"></script> 
    <script> 
    jQuery.noConflict(); 

    // Put all your code in your document ready area 
    jQuery(document).ready(function($){ 
     // Do jQuery stuff using $ 
     $("div").hide(); 
    }); 

    // Use Prototype with $(...), etc. 
    $('someid').hide(); 
    </script> 
</head> 
<body></body> 
</html> 
3
  1. 鏈接jQuery的第一和第二的原型。這將覆蓋$。
  2. 對於jQuery,使用函數jQuery(...)
+0

一個小一點的,我覺得這是因爲當你想使用jQuery的整個頁面(情形如onclick屬性)的最好方法。 – Josiah 2009-06-17 06:16:44

1

你可以使用jQuery.noConflict();然後你可以像這樣重新映射它:$j = jQuery;

+0

或者:var $ j = jQuery.noConflict(); – nickf 2009-06-17 06:09:53

0

您可以使用jQuery的noConflict方法:

var jQ=jQuery.noConflict(); 

現在開始,你可以使用JQ到位「$」與jQuery的功能,並使用$原型。

1

這就是我使用,如果這只是jQuery的

jQuery(function($) { 

    // now you can use $ again within here - this block of code is fired on DOM ready 

});