发送验证码计时器

5年以前  |  阅读数:428 次  |  编程语言:JavaScript 
<input id="send" type="button" value="发送验证码">

var times = 60, // 临时设为60秒

document.getElementById('send').onclick = function () {

     timer = setInterval(function () {

            times--;

            if (times <= 0) {    

                send.value = '发送验证码'; 

                clearInterval(timer);            

                 send.disabled = false;           

                  times = 60; } 

            else {           

                     send.value = times + '秒后重试';          

                      send.disabled = true;        

                }       

         }, 1000);

}  

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8