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);

更多相关文章

  1. 键盘功能无法处理数据表搜索
  2. [求助]如何用JQuery来实现Ctrl+Space完成输入特定字符提示的自动
  3. JQuery自动完成功能不会显示所有结果
  4. 目前最好用的“点击复制”功能,兼容主流浏览器
  5. 用JQuery写的一个简单的验证码功能
  6. 基于jQuery实现页面搜索功能----项目实战
  7. 关于INPUT的autocomplete="off" 属性(浏览器表单默认的记忆功能)
  8. HTML5实现图片预览功能
  9. Web 应用程序学习笔记

随机推荐

  1. golang 如何运行
  2. golang 如何优化
  3. golang 如何处理死锁
  4. golang中如何比较字符串是否相等
  5. golang如何判断channel已经close
  6. golang 如何并发
  7. golang如何调试
  8. golang 如何实现微服务
  9. golang 哪些功能用标准库
  10. golang协程如何关闭