jQuery没有注册$

时间:2009-06-17 05:58:37

标签: javascript jquery

我在网站上使用prototype + jquery。现在原型插件使用$。我不希望jQuery使用$。如何让jQuery不注册$。另外,我如何调用jQuery函数。

感谢您的时间。

5 个答案:

答案 0 :(得分: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>

答案 1 :(得分:3)

  1. 首先链接jquery,然后链接原型。这将覆盖$。
  2. 对于jQuery,请使用函数jQuery(...)

答案 2 :(得分:1)

您可以使用jQuery.noConflict( );然后您可以重新映射它:$j = jQuery;

答案 3 :(得分:1)

这是我使用的,如果它只是一小部分jQuery

jQuery(function($) {

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

});

答案 4 :(得分:0)

您可以使用jquery的noConflict方法:

var jQ=jQuery.noConflict();

现在你可以使用jQ代替“$”来处理jQuery函数并使用$作为原型。