简体   繁体   English

放置.noConflict()以将$修复为Jquery错误

[英]Placing .noConflict() to fix $ to Jquery error

I'm having trouble figuring out where would I place the function try{jQuery.noConflict();}catch(e){}; 我在弄清楚将函数try {jQuery.noConflict();} catch(e){};放在哪里时遇到了麻烦 to get my jquery back in working order.I am new to working with jquery code as well so i do not know where to begin so step by step would help me understand where to actually place the code. 使我的jquery恢复正常工作。我也是使用jquery代码的新手,所以我不知道从哪里开始,所以逐步可以帮助我理解将代码实际放置在哪里。

Firebug points out that there may be conflicting code on the site. Firebug指出网站上可能存在冲突的代码。 The "select state" drop down menu does not work because the javascript is voided. 由于javascript无效,“选择状态”下拉菜单不起作用。

SUBJECT SITE 主题网站

在此处输入图片说明 Stacked Jquery: 堆叠式jQuery:

e()chosen...=0.9.11 (line 9)
e()chosen...=0.9.11 (line 9)
e()chosen...=0.9.11 (line 9)
e(e=select#billing_state.state_select, t=undefined)chosen...=0.9.11 (line 9)
(?)()chosen...=2.0.14 (line 9)
e(r=0)chosen...=0.9.11 (line 9)
a(e=Object[select#billing_state.state_select, select#shipping_state.state_select],   n=function(), r=undefined)jquery.min.js (line 2)

a(e=function(), t=undefined)jquery.min.js (line 2)
e(n=undefined)chosen...=0.9.11 (line 9)
(?)(e=function())chosen...=2.0.14 (line 1)
a(t=[Document /products-page/checkout/, [function()]])jquery.min.js (line 2)
a(e=Document /products-page/checkout/, t=[Document /products-page/checkout/, [function()]])jquery.min.js (line 2)

a(e=undefined)jquery.min.js (line 2)
a()jquery.min.js (line 2)

By using jQuery you would be (by default) using a dollar sign to declare jQuery statements, eg: $('#id').val(); 通过使用jQuery,您(默认情况下)将使用美元符号声明jQuery语句, 例如: $('#id').val(); . However jQuery is not the only JavaScript library that does this. 但是,jQuery不是唯一执行此操作的JavaScript库。

By saying you are trying to get your " jquery back in working order " I assume you have been using it successfully until recently. 通过说您正在尝试使“ jquery恢复正常工作 ”,我认为您直到最近一直在成功使用它。 This may have been caused by adding a new JavaScript Library that also uses a dollar sign for its statements. 这可能是由于添加了一个新的JavaScript库(该语句的语句也使用美元符号)引起的。 To prevent this you are correct in using the noConflict() method, however it does not require a try...catch block. 为避免这种情况,使用noConflict()方法是正确的,但是不需要try...catch块。

The noConflict() method can added a couple of places: noConflict()方法可以添加几个位置:

1) After you have declared/used the jQuery Library: 1)在声明/使用jQuery库后:

<script src="jquery.js"></script>

<script>
  $.noConflict();
  // Code that uses other library's $ can follow here.
</script>

2) You can place it at the very end of your jQuery Library by adding jQuery.noConflict(); 2)您可以通过添加jQuery.noConflict();将其jQuery.noConflict(); jQuery库的jQuery.noConflict(); as the very last line 作为最后一行

Note that when you use noConflict() any jQuery statements afterwards will have to be declared using the jQuery prefix instead of the dollar sign. 请注意 ,当您使用noConflict()之后必须使用jQuery前缀而不是美元符号声明任何jQuery语句。

Additional information can be found on the jQuery API or this Other StackOverflow Answer 可以在jQuery API或此其他StackOverflow答案上找到更多信息。

Regards, 问候,

Grant 格兰特

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM