我这里在setInterval
里判断了timeNum
如果等于0后我把定时器给设为null
怎么还不行
$(".btncaptcha").click(function(){
var _this=this;
if(timeNum>0){
$(this).attr("disabled",true);
timeRun=setInterval(function(){
timeNum-=1;
_this.value="("+timeNum+")s重新获取";
if(timeNum==0){
timeRun=null;
_this.attr("disabled",false);
_this.value="重新获取";
}
},1000);
}
})
不要设置null,那是无效的,这样:
clearInterval(timeRun);
'''清空计时器应该clearInterval
clearInterval(timeRun);