Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

Why isn't jQuery installing?

<!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

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...