admin管理员组文章数量:1426901
I am trying to include an external jQuery file into my html (first time) but it isn't working, just executing the html without the jquery. (css is working fine)
Here's the html code:
<!doctype html>
<head>
<link type="text/css" rel="stylesheet" href="stylesheet.css" />
</head>
<body>
<script type="text/javascript" src="<script src=".min.js" />
<script type="text/javascript" src="script.js"></script>
<h1>Hello World!</h1>`
</body>
</html>
Here's the jquery code in script.js:
$(document).ready(function(){
alert("it works");
});
And yes, they are all in the same folder (dropbox folder actually, but I don't think dropbox affects anything)
I am trying to include an external jQuery file into my html (first time) but it isn't working, just executing the html without the jquery. (css is working fine)
Here's the html code:
<!doctype html>
<head>
<link type="text/css" rel="stylesheet" href="stylesheet.css" />
</head>
<body>
<script type="text/javascript" src="<script src="http://ajax.googleapis./ajax/libs/jquery/1/jquery.min.js" />
<script type="text/javascript" src="script.js"></script>
<h1>Hello World!</h1>`
</body>
</html>
Here's the jquery code in script.js:
$(document).ready(function(){
alert("it works");
});
And yes, they are all in the same folder (dropbox folder actually, but I don't think dropbox affects anything)
Share Improve this question edited Sep 12, 2013 at 1:13 Andrew Barber 40.2k20 gold badges97 silver badges124 bronze badges asked Sep 11, 2013 at 21:40 llpllp 801 gold badge2 silver badges7 bronze badges 4-
1
Where you read this
script
in source? give only your url in source – mit Commented Sep 11, 2013 at 21:45 -
FYI: It's generally accepted to not self-close your
script
tags - do<script src="..."></script>
instead of<script src="..." />
. I believe self-closing script tags work everywhere except old IE (IE7 maybe?), but people still generally don't do it. – Joe Enos Commented Sep 11, 2013 at 21:46 -
If you think about what you have done, you would end up in a Infinite loop because you would put the script in every
src
– iConnor Commented Sep 11, 2013 at 21:52 - Best you can do is learn to debug this error by referring to developer tools for whatever browser you are using. Quick google will help you to get started with developer tools. – Mutant Commented Sep 11, 2013 at 22:00
3 Answers
Reset to default 2<script type="text/javascript" src="<script src="http://ajax.googleapis./ajax/libs/jquery/1/jquery.min.js" />
<script type="text/javascript" src="script.js"></script>
First, remove the extra src="<script
inside your <script>
tag. Also "close" it with a </script>
tag...
<script type="text/javascript" src="http://ajax.googleapis./ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
Second, place the script includes at the end of your <body>
section, just before the </body>
tag:
....
<script type="text/javascript" src="http://ajax.googleapis./ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</body>
OR, anywhere inside your <head>
section:
....
<script type="text/javascript" src="http://ajax.googleapis./ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
....
</head>
And finally, make sure the URL path is correct for your version:
http://ajax.googleapis./ajax/libs/jquery/1.10.2/jquery.min.js
It's always smart to link to a full version. Otherwise, if the code at the URL is updated, your site could suddenly break without warning.
If you make the changes as indicated above and add a <title>
element into your head section...
<head>
<title>Title</title>
....
... your code will then pass HTML validation.
http://validator.w3/check
Is this a typo? You have an extra <script
in your src=" "
<script type="text/javascript" src="<script src="http://ajax.googleapis./ajax/libs/jquery/1/jquery.min.js" />
should be
<script type="text/javascript" src="http://ajax.googleapis./ajax/libs/jquery/1/jquery.min.js"></script>
Change it to:
<script src="http://ajax.googleapis./ajax/libs/jquery/1/jquery.min.js"></script>
You have the full script inside the src, which is wrong.
本文标签: javascriptLinking JQuery into my htmlStack Overflow
版权声明:本文标题:javascript - Linking JQuery into my html - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745487126a2660431.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论