发送验证码后倒计时功能实现
1 function settime(obj) { 2 if (countdown == 0) { 3 obj.removeAttribute("disabled"); 4 var txt = "获取验证码"; 5 $(obj).text(txt); 6 countdown = 60; 7 return; 8 } else { 9 obj.setAttribute("disabled", true); 10 var txt = "重新发送(" + countdown + ")"; 11 $(obj).text(txt); 12 countdown--; 13 } 14 15 setTimeout(function() { 16 settime(obj) 17 }, 1000); 18 }
<button class="btn_yan" onclick="settime(this); return false;">获取验证码</button>
<script>
var countdown = 60;
</script>