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
218 views
in Technique[技术] by (71.8m points)

Why jQuery does not work on my home (local) machine?

My question isn't so much about why a specific bit of jQuery I've written isn't working as it is about no jQuery at all is working; not even working examples I've copied directly from places like W3 Schools.

I use jQuery from time to time in my software development job and while I am by no means an expert, I am pretty familiar with it. For the first time I am trying to use jQuery in a home project and no matter what I do, none of it will work. The example I've included below is about as simple as I can think of, and even it will not work.

<!DOCTYPE HTML>
<html>
<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<div>
    <p>Old Stuff</p>
</div>
<script type="text/javascript">
   $('p').text('New Stuff');
</script>
</body>
</html>

What could possibly be wrong with this?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

The code is ok.

The script is not downloading because, as you probably are not deploying the code, the browser will default to the file:// protocol.

To solve it, add the http: at the script tag:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js">
                                                                           </script>

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

...