jQuery .NoConflict 脚本加载
我试图在高度冲突的环境中使用 jQuery。 .noConflict() 不起作用,我正在尝试做类似的事情,
<script type="text/javascript">
document.write( document.write(unescape("%3Cscript src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));
jQuery.noConflict();
var $ = jQuery;
</script>
有什么想法如何解决这个问题吗?
I am trying to use jQuery in a highly conflict environment. .noConflict() doesn't work and I am trying to do something like
<script type="text/javascript">
document.write( document.write(unescape("%3Cscript src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));
jQuery.noConflict();
var $ = jQuery;
</script>
Any ideas how to fix this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定这与您拥有的事实无关吗:
这会导致错误,然后
noConflict
将不起作用。另外,你需要同时使用 Prototype 和 jQuery 吗?
jQuery.noConflict()
的全部目的是不将jQuery
变量设置为$
因为 Prototype 使用它(我确信有其他原因,但这是本例中的主要原因)。通常,jQuery 和 Prototype 并不是好朋友。最后,您是否绝对肯定(假设您的实际代码中没有语法错误)jQuery 正在加载?
做了一些快速研究。检查此链接,看看它是否有帮助:
http://docs.jquery.com/Using_jQuery_with_Other_Libraries
基本上,您可能必须先调用 jQuery,并且必须在使用
noConflict()
之前调用 PrototypeAre you sure it has nothing to do with the fact that you have:
That would cause an error and then
noConflict
wouldn't work.Also, do you need to be using Prototype and jQuery at the same time? The whole purpose of
jQuery.noConflict()
is to NOT set thejQuery
variable to$
because Prototype uses it (I'm sure there are other reasons, but that's the main one in this case). jQuery and Prototype aren't good friends, usually.Finally, are you absolutely positive (assuming you don't have the syntax error in your real code) that jQuery is getting loaded?
Did some quick research. Check this link and see if it helps any:
http://docs.jquery.com/Using_jQuery_with_Other_Libraries
Basically, you might have to call jQuery first, and you will have to call Prototype BEFORE you use
noConflict()
不要使用
$
- 这是冲突的根源。在您通常使用的地方替换jQuery
,如下所示:等等
Don't use
$
- that is the source of the conflicts. SubstitutejQuery
wherever you'd normally use it, like so:and so on