http://jsbin.com/xoqizaxecu/edit?html,css,js,output
$(".huoqu").on("click",function(){
var $this=$(this);
$this.addClass("gray");
var wait=10;
$this.html(wait+"s后获取");
function fstime(){
if(wait==0){
$(".huoqu").removeClass("gray");
$(".huoqu").text("获取验证码");
wait =10;
}else {
console.log(wait);
$this.addClass("gray");
$(".gray").html(wait+"s后获取");
wait--;
}
}
setInterval(fstime,1000);
});
获取验证码

为什么wait还在无限循环?
console.log 控制台里面 0之后又重新继续计算?
验证码逻辑我问题出在哪句?
如何实现验证码业务问题?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你没清除定时器clearInterval
你的代码用了
setInterval,就是一个无限执行的语句。而且没有停止它,当然会一直执行下去喽
应该等wait等于0时 clearInterval() 你还给wait 赋值10干啥呢