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);
}
}

解决方案 »

  1.   

    http://www.w3cschool.cn/js_timing.html
      

  2.   


    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);//同样,这也是错的
    }

      

  3.   

    没注意你的代码还有问题,更正:把this.x作为参数传递给setTimeout后,将在全局调用,因此第一句中this是不能指向a对象的,更改如下:
    x:function(total){
    total--;
    if(total<0) return;
    document.getElementsByTagName("input")[0].value=this.total;
    window.setTimeout(function(){this.x(total);},1000);
    }
    调用把a.total作为参数调用函数就可以了
      

  4.   

    额,例子:var a={
    total:8,
    x:function(){
    window.setInterval(function(){a.y(a.total);},2000);//定时调用y方法,并传递参数
    },
    y:function(index){alert(index);}

    a.x();