JS实现按钮倒计时

来源:互联网 发布:unity3d itween 编辑:程序博客网 时间:2024/06/06 03:13

点击按钮实现倒计时


<body>

    <input type="button" id="btn" value="免费获取验证码" onclick="settime(this)" /> 
<script type="text/javascript"> 
var countdown=10; 
function settime(val) { 
if (countdown == 0) { 
val.removeAttribute("disabled");    
val.value="免费获取验证码"; 
countdown = 10; 
if(countdown==10){
return;
}
    } else { 
val.setAttribute("disabled", true); 
      val.value="重新发送(" + countdown + ")"; 
countdown--; 
   } 
   
setTimeout(function() { 
settime(val)},1000) 

</script>
  </body>
0 0