jQuery 在我的网站上不起作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19521092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery not working on my site?
提问by user2826739
I tried using jQuery on my website, but it did not seem to work. I figured I was doing something wrong, so I tried copying a codecademy lesson that I completed onto a test site. Here is the code:
我尝试在我的网站上使用 jQuery,但它似乎不起作用。我认为我做错了什么,所以我尝试将我完成的 codecademy 课程复制到测试站点上。这是代码:
HTML
HTML
<!DOCTYPE html>
<html>
<head>
<title>Test Codecademy Lesson</title>
<link rel='stylesheet' type='text/css' href='stylesheet.css'/>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type='text/javascript' src='script.js'></script>
</head>
<body>
<img src="http://i1061.photobucket.com/albums/t480/ericqweinstein/elevator.png"/>
</body>
</html>
CSS
CSS
body {
margin: 0;
padding: 0;
}
img {
position: absolute;
}
Javascript/jQuery
Javascript/jQuery
$(document).ready(function() {
$('img').animate({top:'+=100px'},1000)
});
Is someone able to tell me why this code is not working? My browser is Chrome and I have the latest version.
有人能告诉我为什么这段代码不起作用吗?我的浏览器是 Chrome,我有最新版本。
回答by Dinesh Kanivu
You need to Download the jquery Library and save your local files You can download it from
您需要下载 jquery 库并保存您的本地文件 您可以从
or
或者
you have to use this link
你必须使用这个链接
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
or for the minified version
或者对于缩小版
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js- Version 1.9.1 family, Google hosted
http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js- 版本 1.9.1 系列,谷歌托管
You can refer this also
你也可以参考这个
Is there a link to the "latest" jQuery library on Google APIs?
回答by Nelson
The image won't be loaded by the time document.ready
is fired, better use window.load
so you can see your effect in action, so replace your following code:
图像不会在document.ready
触发时加载,更好地使用window.load
以便您可以看到效果,因此请替换以下代码:
$(document).ready(function() {
for this one:
对于这个:
$(window).load(function() {