首页 > 倒计时怎么停止

倒计时怎么停止

我这里在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);

【热门文章】
【热门文章】