admin管理员组文章数量:1392002
How do I check whether jQuery is loaded in the page or not? I have to run a jQuery script which has a jQuery library link, but when I use the code I want to make sure to load that file only if the page does not have any jQuery file, otherwise use that file. Any suggestions?
How do I check whether jQuery is loaded in the page or not? I have to run a jQuery script which has a jQuery library link, but when I use the code I want to make sure to load that file only if the page does not have any jQuery file, otherwise use that file. Any suggestions?
Share Improve this question edited Dec 21, 2011 at 19:32 Adam 45k17 gold badges107 silver badges145 bronze badges asked Dec 21, 2011 at 19:27 disckydiscky 15.3k8 gold badges22 silver badges11 bronze badges4 Answers
Reset to default 7if (typeof jQuery == 'undefined') {
// This means jQuery is not loaded
}
Also, take a look at yepnope.js, it allows you to load different JavaScript files based on if certain conditions are true or false.
if (typeof jQuery != 'undefined') {
// jQuery is loaded
}
The simplest:
if( window.jQuery ) {
// you code here
}
To check if jQuery is loaded on the page try:
if (!(window.jQuery || window.$)){
//then load it
} else {
//already loaded
}
本文标签: javascriptHow to check whether the jQuery file is loaded on the page or notStack Overflow
版权声明:本文标题:javascript - How to check whether the jQuery file is loaded on the page or not? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744759698a2623680.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论