如下
//这里我也不知道为什么需要强制设置一下才生效
//下面为激活方法
countdown = 60;
$("#yzm").val("重新发送(" + countdown + ")");
settime($("#yzm"));
//下面为设置方法
var countdown = 0;
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)
}
//button
<input type="button" id="yzm" class='btn' value="获取验证码" onclick="getvfcode();" />