div{
float:left;
width:100px;
height:35px;
line-height:35px;
text-align:center;
border:1px solid gold;
}
function $(id){return document.getElementById(id)}
function change(){
console.log('xx');
console.log(this);
this.style.background="orange";
}
function test1(){
var block=$('box').childNodes;
var i=1,j=1;
var delay=function(){change.call(block[1])};
setTimeout(delay,1*1000+j*500);
delay=function(){change.call(block[3])};
setTimeout(delay,3*1000+j*500);
}
function test2(){
var block=$('box').childNodes;
var i=1,j=1;
for(var j=0;j
if(1==block[j].nodeType ){
var delay=function(){change.call(block[j])};
setTimeout(delay,i*1000+j*500);
}
}
}
test1();
运行代码
复制代码
另存代码
提示:您可以先修改部分代码再运行