在Rails应用程序中结合Scriptaculous和jQuery [英] Combining Scriptaculous and jQuery in a Rails application
本文介绍了在Rails应用程序中结合Scriptaculous和jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到以下情况
- 利用rjs / Scriptaculous提供AJAX功能的rails应用程序
- 使用jQuery编写的很多不错的javascript(用于单独的应用程序)
我想将两者结合起来在我的Rails应用程序中使用基于jQuery的功能,但我担心jQuery和Scriptaculous冲突(它们都定义了$()函数等)。
I want to combine the two and use my jQuery based functionality in my Rails application, but I'm worried about jQuery and Scriptaculous clashing (they both define the $() function, etc).
将两者结合在一起的最简单方法是什么?谢谢!
What is my easiest option to bring the two together? Thanks!
推荐答案
jQuery.noConflict();
然后使用jQuery代替$来引用jQuery。例如,
Then use jQuery instead of $ to refer to jQuery. e.g.,
jQuery('div.foo').doSomething()
如果你需要调整使用$的jQuery代码,你可以用它包围它:
If you need to adapt jQuery code that uses $, you can surround it with this:
(function($) {
...your code here...
})(jQuery);
这篇关于在Rails应用程序中结合Scriptaculous和jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文