<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script src="js/miaov.js" ></script>
<script>
window.onload=function(){
var str='';
var len=20;
var num=0;
var aDiv=document.getElementsByTagName('div')
var timer=null;
var onOff=true;
for( var i=0;i<len;i++){
str+='<div style="width:50px;height:50px;background:red; position:absolute; top:0; left:'+i*60+'px;"></div>'
}
document.body.innerHTML=str;
document.onclick=function(){
if(true){
clearInterval(timer)
timer=setInterval(function(){
doMove(aDiv[num],'top',20,500)
num++;
if(num===len){
clearInterval(timer)
}
},100)
onOff=false;
}else{
clearInterval(timer)
timer=setInterval(function(){
doMove(aDiv[num],'bottom',20,500)
num++;
if(num===len){
clearInterval(timer)
}
},100)
onOff=true;
}
}
}
</script>
</head>
<body>
</body>
</html>
说一个问题:
你获取aDiv时,页面上还没有任何 div ,后面自然无法执行了。
话说: 你调程序都是看效果来黑箱测试的吗?下个断点很容易就看得出来啊