jQuery没有在我的网站上工作?

时间:2013-10-22 14:45:07

标签: javascript jquery html css

我尝试在我的网站上使用jQuery,但似乎没有用。我认为我做错了什么,所以我尝试将我完成的codecademy课程复制到测试网站上。这是代码:

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

body {
    margin: 0;
    padding: 0;
}
img {
position: absolute;
}

使用Javascript / jQuery的

$(document).ready(function() {
    $('img').animate({top:'+=100px'},1000)
});


有人能告诉我为什么这段代码不起作用? 我的浏览器是Chrome,我有最新版本。

2 个答案:

答案 0 :(得分:6)

您需要下载jquery库并保存本地文件您可以从

下载它

http://jqueryui.com/

你必须使用这个链接

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>

或缩小版

<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 - 版本1.9.1系列,Google托管

您也可以参考

Is there a link to the "latest" jQuery library on Google APIs?

答案 1 :(得分:2)

document.ready被触发时不会加载图片,最好使用window.load以便您可以看到效果,请替换以下代码:

$(document).ready(function() {

这个:

$(window).load(function() {
相关问题