js60秒倒计时

第一篇博客就用来记录一个刚刚理解的60秒倒计时,用来发验证码再合适不过了

var countdown=60;
function countdown(){
var obj = $("#identifying");
settime(obj);
getcode();    //向后台传值函数

}
function settime(obj) { //发送验证码倒计时
if (countdown === 0) {
obj.attr('disabled',false);
//obj.removeattr("disabled");
obj.val("免费获取验证码");
countdown = 60;
return;
} else {
obj.attr('disabled',true);
obj.val("重新发送(" + countdown + ")");
countdown--;
}
setTimeout(function() {
settime(obj) }
,1000)
}

猜你喜欢

转载自www.cnblogs.com/txbblog/p/10225881.html