如何查看页面上是否加载了jQuery文件

How to check whether the jQuery file is loaded on the page or not?

本文关键字:加载 jQuery 文件 是否 何查看      更新时间:2023-09-26

如何检查页面中是否加载了jQuery ?我必须运行一个jQuery脚本,其中有一个jQuery库链接,但当我使用的代码,我要确保加载该文件,只有当页面没有任何jQuery文件,否则使用该文件。有什么建议吗?

if (typeof jQuery == 'undefined') {
   // This means jQuery is not loaded
}

另外,看看yepnope.js,它允许你加载不同的JavaScript文件,如果某些条件是真或假。

if (typeof jQuery != 'undefined') {
 // jQuery is loaded
}

最简单的:

if( window.jQuery ) { 
 // you code here 
} 

查看是否加载了jQuery:

if (!(window.jQuery || window.$)){
 //then load it
} else {
//already loaded
}