手机短信验证码倒计时,必须用button或者用input的type='button'
var countdown=60;
function settime(obj) {
if (countdown == 0) {
obj.removeAttribute("disabled");
obj.innerHTML="免费获取验证码";
countdown = 60;
return;
} else {
obj.setAttribute("disabled", true);
obj.innerHTML="重新发送(" + countdown + ")";
countdown--;
}
setTimeout(function() {
settime(obj) }
,1000)
}
$('#btn').on('click',function(e){
settime(this);
})
例如
<button type="button" id="btn">免费获取验证码</button>