jQuery 和 Prototype 之间的冲突
我正在构建一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将 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(...
我假设最好的插件是针对 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! :)