我这奇葩代码,为啥倒数到2就停了
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript">
window.onload=function(){
var send=document.getElementById('send'),
times=5,
timer=null;
send.onclick=function(){
// 计时开始
function countDown(){
send.value = times + "秒后重试";
send.disabled=true;
times--;
if(times <= 0){
clearInterval(timer);
send.disabled=false;
times=5;
send.value = "发送验证码";
}
}
timer=setInterval(countDown,1000);
}
}
</script>
</head>
<body>
<input type="button" id="send" value="发送验证码">
</body>
</html>