文章

Checking if jquery is loaded using Javascript

If jQuery isn't loaded then \$() won't even run at all and your callback won't execute, unless you're using another library and that library happens to share the same \$() syntax.

原文: https://stackoverflow.com/questions/7341865/checking-if-jquery-is-loaded-using-javascript

Well, you are using jQuery to check for the presence of jQuery. If jQuery isn’t loaded then $() won’t even run at all and your callback won’t execute, unless you’re using another library and that library happens to share the same $() syntax.

Remove your $(document).ready() (use something like window.onload instead):

1
2
3
4
5
6
7
8
9
10
#!javascript
window.onload = function() {
    if (window.jQuery) {  
        // jQuery is loaded  
        alert("Yeah!");
    } else {
        // jQuery is not loaded
        alert("Doesn't Work");
    }
}
本文由作者按照 CC BY 4.0 进行授权