代码只执行一次,再点击就没用了
<!doctype html> <html> <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-- send.value=times+"秒后重试" send.disabled=true if(times<=50){ clearInterval(timer); send.disabled=false send.value="发送验证码"; } },1000); } } </script> </head> <body> <input type="button" id="send" value="发送验证码"> </body> </html>