jQuery 和 Prototype 之间的冲突

发布于 2024-11-04 07:17:33 字数 1150 浏览 0 评论 0原文

我正在构建一个 Rails 应用程序并安装这个名为“best-in-place”的 gem 进行一次性编辑。它工作了一段时间,但在我与 jQuery 和 Prototype 冲突作斗争之后,它停止工作,现在我在尝试加载页面时收到此错误消息。

错误http:// /dl.getdropbox.com/u/3481269/Screen%20shot%202011-04-30%20at%206.17.45%20PM.png

我同时包含 jQuery 和原型 JS 文件。

    <script src="/javascripts/jquery.js?1303396383" type="text/javascript"></script> 
<script src="/javascripts/rails.js?1303562965" type="text/javascript"></script> 
<script src="/javascripts/application.js?1303842064" type="text/javascript"></script> 

    <script language="javascript" type="text/javascript"> 
        $j = jQuery.noConflict();
    </script> 

    <script src="/javascripts/prototype.js?1303686720" type="text/javascript"></script> 
<script src="/javascripts/jquery.purr.js?1302145859" type="text/javascript"></script> 
<script src="/javascripts/best_in_place.js?1302150372" type="text/javascript"></script> 

您能帮我解决导致此错误的可能原因吗?

I am building a rails application and installing this gem called "best-in-place" for one-time editing. It was working for a while, but after I struggled with jQuery and Prototype conflicts, it stopped working and now I get this error message when trying to load the page.

error http://dl.getdropbox.com/u/3481269/Screen%20shot%202011-04-30%20at%206.17.45%20PM.png

I am including both the jQuery and prototype JS files.

    <script src="/javascripts/jquery.js?1303396383" type="text/javascript"></script> 
<script src="/javascripts/rails.js?1303562965" type="text/javascript"></script> 
<script src="/javascripts/application.js?1303842064" type="text/javascript"></script> 

    <script language="javascript" type="text/javascript"> 
        $j = jQuery.noConflict();
    </script> 

    <script src="/javascripts/prototype.js?1303686720" type="text/javascript"></script> 
<script src="/javascripts/jquery.purr.js?1302145859" type="text/javascript"></script> 
<script src="/javascripts/best_in_place.js?1302150372" type="text/javascript"></script> 

Can you help me trouble-shoot what might be the cause for this error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ら栖息 2024-11-11 07:17:33

您将 jQuery .noConflict() 方法分配给 $j,因此对于 jQuery 内容,您现在必须使用 $j 而不是 $< /code> 例如 $j(document).ready(...

You are assigning the jQuery .noConflict() method to $j so for jQuery stuff you must now use $j not $ so for instance $j(document).ready(...

渡你暖光 2024-11-11 07:17:33

我假设最好的插件是针对 jQuery 的,所以如果我弄错了,请原谅其余的内容。除非您在应用程序中编写了大量依赖于 Prototype 的 JS,否则我可能会放弃它而转而使用 jQuery。进行切换非常容易

尽管可以使用适当的命名空间来使用两者,但这并不值得。两者之间存在大量重叠,并且您为代码添加了很多额外的重量。一个 JavaScript 框架应该足够一页了! :)

I'm assuming that the best-in-place plugin is for jQuery, so forgive the rest of this if I'm mistaken. Unless you have written a ton of JS that depends on Prototype in your app, I'd probably ditch it in favor of jQuery. It's pretty easy to make the switch.

Even though it's possible to use both with proper namespacing, it's not worth it. There's a massive amount of overlap between the two, and you're adding a lot of extra weight to your code. One JavaScript framework should be enough for one page! :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文