<input type="button" id="btn" value="免费获取验证码" onclick="settime(this)" />
<script type="text/javascript">
var countdown=60;
function settime(val) {
if (countdown == 0) {
val.removeAttribute("disabled");
val.value="免费获取验证码";
countdown = 60;
} else {
val.setAttribute("disabled", true);
val.value="重新发送(" + countdown + ")";
countdown--;
}
setTimeout(function() {
settime(val)
},1000)
}
</script>
Could you please tell me that when the time times out after using this code, the method will automatically loop, but after deleting the setTimeout method, the code function cannot be realized. How to solve it?
Add a return ; and that’s it. I gave it a try.
<input type="button" id="btn" value="Get verification code for free" onclick="settime(this)" />
<script type="text/javascript">
</script>