Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

<!doctype html>
<html>
<head>
<title>jQuery install test</title>

<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<script type="text/javascript" src="jquery.min.js"></script>

<style type="text/css"></style>

</head>

<body>

<script>

    if (typeof jQuery != "undefined"){
        alert("jQuery is installed");
    } else {
        alert("jQuery is not installed");
    }

</script>

</body>
</html>

For some reason I am unable to embed jQuery. I named the jQuery file I downloaded jquery.min.js. I also tried changing the src to "http://ajax.googleapis.com/ajax/libs/jquery/latest/jquery.js" but that didn't work as well. Is there a problem with my code? I am new to programming.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
147 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try using window.onload which check after all DOM is loaded

window.onload = function() {
    if (window.jQuery) {  
        alert("jQuery is loaded");
    } else {
        alert("jQuery is not loaded");
    }
}

OR Use

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>

Demo


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...