在Rails应用程序中结合Scriptaculous和JQuery
16lz
2021-01-22
I've got the following situation
我有以下情况
- A rails application that makes use of rjs / Scriptaculous to offer AJAX functionality
- 一个rails应用程序,它使用rjs / Scriptaculous来提供AJAX功能
- Lot of nice javascript written using JQuery (for a separate application)
- 使用JQuery编写的很多很好的javascript(用于单独的应用程序)
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).
我想结合两者并在我的Rails应用程序中使用基于JQuery的功能,但我担心JQuery和Scriptaculous冲突(它们都定义了$()函数等)。
What is my easiest option to bring the two together? Thanks!
将两者结合在一起的最简单方法是什么?谢谢!
3 个解决方案
#1
15
jQuery.noConflict();
Then use jQuery instead of $ to refer to jQuery. e.g.,
然后使用jQuery而不是$来引用jQuery。例如。,
jQuery('div.foo').doSomething()
If you need to adapt jQuery code that uses $, you can surround it with this:
如果你需要调整使用$的jQuery代码,你可以用它包围它:
(function($) {
...your code here...
})(jQuery);
更多相关文章
- 键盘功能无法处理数据表搜索
- [求助]如何用JQuery来实现Ctrl+Space完成输入特定字符提示的自动
- JQuery自动完成功能不会显示所有结果
- 目前最好用的“点击复制”功能,兼容主流浏览器
- 用JQuery写的一个简单的验证码功能
- 基于jQuery实现页面搜索功能----项目实战
- 关于INPUT的autocomplete="off" 属性(浏览器表单默认的记忆功能)
- HTML5实现图片预览功能
- Web 应用程序学习笔记