0

我最近在学习 javascript + jquery,尝试将 jquery 导入 html 时遇到问题。

我从互联网上得到了下面的代码,而我尝试从

<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'></script>

<script type='text/javascript' src='jquery.js'></script>

它不起作用,脚本不执行。

我确定文件“jquery.js”与 html 文件是同一个文件夹,并且 jquery.js 是从http://jquery.com/download/下载的(我确实将文件名更改为“jquery.js”而不是它原来的长名)

我可能会犯什么错误?

html代码:

<!DOCTYPE html>
<html>
<head>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'></script>
<script> 
$(document).ready(function(){
  $("button").click(function(){
    $("div").animate({left:'250px'});
  });
});
</script> 
</head>

<body>
<button>Start Animation</button>
<p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!</p>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;">
</div>

</body>
</html>
4

1 回答 1

1

这对我来说在 chrome 中效果很好:

<!DOCTYPE html>
<html>
<head>
<script src='jquery.js'></script>
<script> 
$(document).ready(function(){
  $("button").click(function(){
    $("div").animate({left:'250px'});
  });
});
</script> 
</head>

<body>
<button>Start Animation</button>
<p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!</p>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;">
</div>

</body>
</html>

使用此版本的 Jquery http://code.jquery.com/jquery-1.8.2.min.js的本地副本

于 2012-10-09T09:13:23.310 回答