为什么放在head里就不生效了
这里是一定要放在body里么
这里是一定要放在body里么
2016-05-12
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script> <script type="text/javascript"> $(function(){ $("#btn1").bind("click",function(){ $("div").animate( {left:"-=50px"},3000) }); $("#btn2").bind("click",function(){ $("div").animate( {left:"+=50px"},3000) }) } </script>
你要是放在head里面的话,就要加$(function(){ //代码 }
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery动画特效</title>
<style type="text/css">
div{
position:absolute;
top:50px;
left:200px;
height:50px;
width:50px;
border:1px solid red;
}
</style>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$("#btn1").bind("click",function(){
$("div").animate(
{left:"-=50px"},3000)
});
$("#btn2").bind("click",function(){
$("div").animate(
{left:"+=50px"},3000)
})
</script>
</head>
<body>
<div>hello world!</div><br/>
<input type="button" id="btn1" value="左移"/>
<input type="button" id="btn2" value="右移"/>
</body>
</html>
举报