【问题标题】:Use both jquery.js and scriptaculous.js files?同时使用 jquery.js 和 scriptaculous.js 文件?
【发布时间】:2009-08-04 11:05:25
【问题描述】:

有没有办法同时使用 jquery 和 scriptaculous js 文件?

我正在尝试实现 cakephp 框架的自动完成功能,它需要 js 文件、prototype.js、scriptaculous.js、effects.js 和 controls.js。

我还在需要 jquery.js 文件的应用程序中使用 JQuery 函数。

如果我包含 jquery.js 文件,自动完成功能将不起作用。但我还需要 jquery.js 文件来实现我的 jquery 函数。

那么有什么方法可以同时使用这两个js文件吗?

【问题讨论】:

标签: jquery cakephp prototypejs conflict scriptaculous


【解决方案1】:

您需要在 jQuery 中启用无冲突模式,请参阅:

http://docs.jquery.com/Using_jQuery_with_Other_Libraries

从上面的链接:

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

     // Use jQuery via jQuery(...)
     jQuery(document).ready(function(){
       jQuery("div").hide();
     });

     // Use Prototype with $(...), etc.
     $('someid').hide();
   </script>
 </head>
 <body></body>
</html>

但是,您仍然需要加载 Prototype 才能使 Scriptaculous 工作。作为一个建议,如果您只是(或主要)将那些其他库用于自动完成器小部件,您可能想尝试一下 jQuery's autocomplete plugin

【讨论】:

    【解决方案2】:

    同时使用 jQuery 和 Scriptaculous 最简单的方法是:

    var $j = jQuery.noConflict();
    

    在 jQuery 中使用 $j 而不是 $

    例如$j('#id')

    【讨论】:

      猜你喜欢
      • 2014-04-23
      • 2022-01-17
      • 1970-01-01
      • 2013-01-07
      • 1970-01-01
      • 2014-01-30
      • 2012-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多