js,JQ获取短信验证码倒计时

时间:2021-04-26 15:49:07

按钮

<a href="javasript:void(0);"onclick="settime(this);">获取手机验证码</a>

倒计时js

    <script>
var countdown=60;
function settime(obj) {
if (countdown == 0) {
obj.getAttributeNode('onclick').value ="settime(this);";
obj.textContent="免费获取验证码";
countdown = 60;
return;
} else {
obj.getAttributeNode('onclick').value ="javascript:void(0);";
obj.setAttribute("disabled", true);
obj.textContent="重新发送(" + countdown + ")";
countdown--;
}
setTimeout(function() {
settime(obj)
},1000)
}
</script>