您的位置:首页 > Web前端 > JavaScript

按钮发送验证码等待时间效果——定时器setInterval使用

2016-04-28 15:39 846 查看




<!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=60;
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息