实现点击按钮发送短信验证码后60秒倒计时

<button id="numbtn">获取验证码</button>

// 获取验证码倒计时

var countdown = 60;

$('#numbtn').on('click',function(){

var obj = $("#numbtn");

settime(obj);

})

function settime(obj) { //发送验证码倒计时

if (countdown == 0) {

obj.attr('disabled', false);

//obj.removeattr("disabled");

obj.html("免费获取验证码");

countdown = 60;

return;

} else {

obj.attr('disabled', true);

obj.html("重新发送(" + countdown + ")");

countdown--;

}

setTimeout(function () {

settime(obj)

}

, 1000)

}

猜你喜欢

转载自blog.csdn.net/weixin_42615523/article/details/81216633