<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#div1{
width:200px;
height:200px;
border:2px solid red;
position:absolute;
left:0px;
top:0px;
}
</style>
<script type="text/javascript">
function startqwe(){
var qwe=document.getElementById('div1');
function moveqwe(){
qwe.style.left=qwe.style.offsetLeft+10+'px';
}
setInterval(moveqwe(),30);
}
</script>
</head>
<body>
<div id="div1"></div>
<input type="button" value="点击开始运动" onclick="startqwe()" />
</body>
</html>
#div1{ width:200px; height:200px; border:2px solid red; position:absolute; left:0px; top:0px; } 加个z-index:-1; qwe.style.left=qwe.style.offsetLeft+10+'px'; 改成 qwe.style.left=qwe.offsetLeft+10+'px';
<script type="text/javascript">
function startqwe(){
var qwe=document.getElementById('div1');
qwe.style.left=qwe.offsetLeft+10+'px';
alert(qwe.style.left);
setInterval(startqwe,100);
//此处不能写startqwe();
}
</script>