2009-06-17 143 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 

});