如何让jQuery与Prototype一起使用 [英] How to get jQuery to work with Prototype
问题描述
好的,这就是这种情况.一直在拉我的头发.
Ok so here is the situation. Been pulling my hair out on this one.
我是这个菜鸟.仅使用导轨约6周.我使用的是标准安装程序包,我的代码充分利用了原型帮助器.就像我说的,菜鸟;)
I'm a noob at this. Only been using rails for about 6 weeks. I'm using the standard setup package, and my code leverages prototype helpers heavily. Like I said, noob ;)
因此,我尝试添加一些jQuery效果,例如PrettyPhoto.但是发生的是,当页面首次加载时,PrettyPhoto的效果很好.但是,一旦有人使用Prototype帮助器(例如使用link_to_remote创建的链接),Prettyphoto就会停止工作.
So I'm trying to put in some jQuery effects, like PrettyPhoto. But what happens is that when the page is first loaded, PrettyPhoto works great. However, once someone uses a Prototype helper, like a link created with link_to_remote, Prettyphoto stops working.
我已经尝试过jRails,它是JQuery站点上建议的所有修复程序,用于阻止冲突...
I've tried jRails, all of the fixes proposed on the JQuery site to stop conflicts...
http://docs.jquery.com/Using_jQuery_with_Other_Libraries
...甚至做了一些疯狂的事情,例如将prototype.js中的所有$重命名为$$都无济于事.要么原型帮助程序中断,要么jQuery中断.
...even done some crazy things likes renaming all of the $ in prototype.js to $$$ to no avail. Either the prototype helpers break, or jQuery breaks.
似乎我什么也做不了,可以让它们一起工作.
Seems nothing I do can get these to work together.
有什么想法吗?
这是我的application.html.erb
Here is part of my application.html.erb
<%= javascript_include_tag 'application' %>
<%= javascript_include_tag 'tooltip' %>
<%= javascript_include_tag 'jquery' %>
<%= javascript_include_tag 'jquery-ui' %>
<%= javascript_include_tag "jquery.prettyPhoto" %>
<%= javascript_include_tag 'prototype' %>
<%= javascript_include_tag 'scriptalicious' %>
</head>
<body>
<script type="text/javascript" charset="utf-8">
jQuery(document).ready(
function() {
jQuery("a[rel^='prettyPhoto']").prettyPhoto();
});
</script>
如果我将原型放在jquery之前,那么原型助手将无法工作 如果我放入noconflict子句,那么两个都行不通.
If I put prototype before jquery, the prototype helpers don't work If I put the noconflict clause in, neither works.
提前谢谢!
克里斯
顺便说一句:当我尝试此操作时,来自jQuery网站:
BTW: when I try this, from the jQuery site:
<script>
jQuery.noConflict();
// Use jQuery via jQuery(...)
jQuery(document).ready(function(){
jQuery("div").hide();
});
// Use Prototype with $(...), etc.
$('someid').hide();
</script>
我的页面消失了!
推荐答案
您应使用jQuery.noConflict();
,此后所有对jquery的调用应仅使用jQuery()
代替of $()
you should use jQuery.noConflict();
and after this all calls to jquery should be done only using the jQuery()
instead of $()
这篇关于如何让jQuery与Prototype一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!