javascript 添加无冲突js后未定义的jQuery
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24307790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Undefined jQuery after adding no conflict js
提问by user3756611
I've added jquery 1.8.2 to both my page.xml file and the corresponding directory.. however i am still getting multiple Uncaught ReferenceError: jQuery is not defined errors. I have checked to make sure jquery is loaded as well as noconflict.js. I have also disabled the two jquery versions to see if that would make a difference.
我已经将 jquery 1.8.2 添加到我的 page.xml 文件和相应的目录中..但是我仍然收到多个 Uncaught ReferenceError: jQuery is not defined 错误。我已经检查以确保加载了 jquery 以及 noconflict.js。我还禁用了两个 jquery 版本,看看这是否会有所作为。
The magento version i am using is ver 1.8.1.0
我使用的 magento 版本是 1.8.1.0
Jquery no conflict has been added. (no conflict.js gets undefinded error too)
Jquery 没有添加冲突。(没有冲突。js 也会出现未定义的错误)
After adding no conflict js i wrote js like this
添加无冲突js后我写了这样的js
$j(document).ready(function(){
// write your code here
});
In the page.xml file the script src is
在 page.xml 文件中,脚本 src 是
jquery-1.8.2.min.js and it is the first script.
jquery-1.8.2.min.js 它是第一个脚本。
<block type="page/html_head" name="head" as="head">
<action method="addJs"><script>jquery-1.8.2.min.js</script></action>
<action method="addJs"><script>no-conflict.js</script></action>
<action method="addJs"><script>prototype/prototype.js</script></action>
<action method="addJs"><script>lib/ccard.js</script></action>
<action method="addJs"><script>prototype/validation.js</script></action>
ect.
等。
the errors look like this ($j error if after i added $j document function to file) :
错误看起来像这样(如果在我将 $j 文档函数添加到文件后,则为 $j 错误):
Uncaught ReferenceError: $j is not defined guytgunter.com/shop/~/jquery-1.8.2.min.js:2
Uncaught ReferenceError: jQuery is not defined guytgunter.com/shop/~/no-conflict.js:1
Uncaught ReferenceError: jQuery is not defined guytgunter.com/shop/~/ddaccordion.js:249
Uncaught ReferenceError: jQuery is not defined guytgunter.com/shop/~/ddaccordion.js:151
Uncaught ReferenceError: jQuery is not defined guytgunter.com/shop/~/jquery.colorbox-min.js:7
Uncaught ReferenceError: jQuery is not defined guytgunter.com/shop/:221
Uncaught ReferenceError: jQuery is not defined guytgunter.com/shop/:283
Uncaught ReferenceError: jQuery is not defined guytgunter.com/shop/:644
Uncaught ReferenceError: jQuery is not defined wecreater.com/web/~/responsiveslides.min.js:170
Uncaught ReferenceError: jQuery is not defined wecreater.com/magento/~/noConflict.js:1
Uncaught ReferenceError: jQuery is not defined
回答by Mageotron
1.Check for the order for js inclucded
1.检查js包含的顺序
2.Check for the jQuery URL loaded properly
2.检查是否正确加载了jQuery URL
3.Check for any other version of jquery used in the website and disable it
3.检查网站中使用的任何其他版本的jquery并禁用它
This will do the job !!!!
这将完成工作!!!!
回答by aforankur
If you are using $j, then before writing your script add following line within Script tag -
如果您使用 $j,则在编写脚本之前在 Script 标签中添加以下行 -
$j = jQuery.noConflict();
$j = jQuery.noConflict();
Then proceed with $j.
然后继续$j。
Also make sure you are using Single jQuery library.
还要确保您使用的是 Single jQuery 库。
You can check this using Browser Short key Ctrl+Uto see the view-source. With the help of this you can check whether library including once or twice.
您可以使用浏览器快捷键Ctrl+U来查看查看源代码。借助此功能,您可以检查库是否包含一次或两次。
回答by Shaun O'Hagan
One simple mistake I've made in the past is to try using jQuery in the Magento head.phtml file. At this time in the processing cycle the page.xml file won't have been processed and JQuery / noconflict will not be defined even though you'll of course see it when you view source on your page.
我过去犯过的一个简单错误是尝试在 Magento head.phtml 文件中使用 jQuery。此时在处理周期中,page.xml 文件将不会被处理并且不会定义 JQuery/noconflict,即使您在页面上查看源代码时当然会看到它。