To detect if the jquery library is already loaded, you can use the following JavaScript code:
if (typeof JQuery! = ' undefined ') {
Alert ("JQuery library is loaded!");
}Else{
Alert ("JQuery Library is not found!");
}
Another option.
In some blogs and forums it is mentioned that you can use code to achieve the same purpose.
If
Alert ("JQuery library is loaded!");
}Else{
Alert ("JQuery Library is not found!");
}
However, this would not work, and when the jquery library was not loaded, the above code would fail (jquery was not defined as jqueryis not define), and the warning message would not be executed.
Finally, a jquery detection code is often recommended.
<title>jquery Library is loaded or not</title>
<body>
<script type= "Text/javascript" src= ". /jquery-1.11.1.min.js "></script>
<script type= "Text/javascript" >
if (typeof jquery!= ' undefined ') {
Alert ("JQuery library is loaded!");
} else{
Alert ("JQuery library is not found");
}
if (jQuery) {
Alert ("JQuery library is loaded!");
}else{
Alert ("JQuery Library is not found!");
}
</script>
</body>
1 The effect diagram of the jquery is loaded:
After clicking OK:
<title>jquery Library is loaded or not</title>
<body>
<script type= "Text/javascript" src= ". /jquery-1.11.108.min.js "></script>
<script type= "Text/javascript" >
if (typeof jquery!= ' undefined ') {
Alert ("JQuery library is loaded!");
} else{
Alert ("JQuery library is not found");
}
if (jQuery) {
Alert ("JQuery library is loaded!");
}else{
Alert ("JQuery Library is not found!");
}
</script>
</body>
The effect of changing the name of the jquery library to a nonexistent name:
After clicking OK:
Summarize:
As you can see, the first method is correct and the second method is flawed.