js 点击获取验证码后的倒数60s

时间:2022-01-14 09:52:39
<!DOCTYPE html>
<html> <head>
<meta charset="UTF-8" />
<script type="text/javascript">
window.onload = function() {
var getCheckNum = document.getElementById("getCheckNum");
getCheckNum.onclick = function() {
settime(this)
}
}
var countdown = 60; function settime(obj) {
if(countdown == 0) {
obj.removeAttribute("disabled");
obj.value = "免费获取验证码";
countdown = 60;
return;
} else {
obj.setAttribute("disabled", true);
obj.value = countdown + "s";
countdown--;
}
setTimeout(function() {
settime(obj)
}, 1000)
}
</script>
</head> <body>
<input type="button" class="getCheckNum" id="getCheckNum" value="免费获取验证码" />
</body> </html>