var a={
total:8,
x:function(){
this.total--;
document.getElementsByTagName("input")[0].value=this.total;
window.setTimeout(this.x(),1000);
},
m:function(){
window.setInterval(,1000);
}
}
total:8,
x:function(){
this.total--;
document.getElementsByTagName("input")[0].value=this.total;
window.setTimeout(this.x(),1000);
},
m:function(){
window.setInterval(,1000);
}
}
var a={
total:8,
x:function(){
this.total--;
document.getElementsByTagName("input")[0].value=this.total;
window.setTimeout(this.x(),1000);//这句写错了,第一个参数应该是一个函数,你这样写传的是函数的返回值,把x后面的括号去掉;并且这句属于递归调用,但是这个递归没有出口条件,要加上,避免无限递归,可在第一句下面加上:if(this.total<0) return;就可以了},
m:function(){
window.setInterval(,1000);//同样,这也是错的
}
}
x:function(total){
total--;
if(total<0) return;
document.getElementsByTagName("input")[0].value=this.total;
window.setTimeout(function(){this.x(total);},1000);
}
调用把a.total作为参数调用函数就可以了
total:8,
x:function(){
window.setInterval(function(){a.y(a.total);},2000);//定时调用y方法,并传递参数
},
y:function(index){alert(index);}
}
a.x();