用javascript实现发送验证码和60秒计时重试

来源:互联网 发布:淘宝联盟推广链接图片 编辑:程序博客网 时间:2024/05/22 19:43

用javascript实现:

点击“发送验证码”按钮后,按钮依次显示为“59秒后重试”、“58秒后重试”…直至倒计时至0秒时再恢复显示为“发送验证码”。在倒计时期间按钮为禁用状态.

<!doctype html><html lang="en"><head>    <meta charset="UTF-8"><title>Document</title><script type="text/javascript">window.onload=function(){    var send=document.getElementById('send'),        times=60,        timer=null;    send.onclick=function(){      // 计时开始            timer=setInterval(function(){            times--;        if(times<=0){            send.value='发送验证码';            clearInterval(timer);            times=10;            send.disabled=false;        }else{            send.value=times+'秒后重试'            send.disabled=true;        }console.log(times)    },1000)           } }</script></head><body><input type="button" id="send" value="发送验证码"></body></html>



0 0