Reprinted from Http://www.jb51.net/article/27185.htm
Whether a test class, method, variable, or property already exists is a basic JavaScript programming knowledge. We're here to detect if the jquery () or $ () function exists
Of course, this approach is not limited to jquery detection, and is common to any JavaScript variable or function.
The jquery () or $ () function will be defined after the current web page loads jquery, so there are 2 ways to detect if jquery is already loaded:
Method 1:
Copy the Code code as follows:
if (jQuery) {
JQuery is loaded
} else {
JQuery is not loaded
}
Method 2:
Copy the Code code as follows:
if (typeof jQuery = = ' undefined ') {
JQuery is not loaded
} else {
JQuery is loaded
}
Note:
This is a safe and reliable way to detect if the jquery function has been defined above, because when you load jquery.js, you may reload prototype.js or mootools.js, which may redefine the $ () function to detect $ () Whether the function exists will be inaccurate.
Detects if the jquery.js has loaded judgment code