|  | 
 
|   
原生JS:获取验证码间隔
x
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
 复制代码<!doctype html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<title>获取验证码间隔</title>
<style>
a{background:none repeat scroll 0 0 #f4f4f4;border:1px solid #dddddd;color:#333;display:inline-block;height:36px;line-height:36px;margin-left:10px;margin-top:0;padding:0;text-align:center;text-decoration:none;padding:0 10px;}
</style>
</head>
<body>
<a href="javascript:void(0);" id="view">获取验证码间隔</a>
<script>
var t,timer,
view=document.getElementById('view'),bState = true;
function gain(){
t=10;clearInterval(timer);
timer=setInterval(function(){
bState = false;
view.innerHTML = "<b>" + t + "</b>秒后重新获取";
if(t==0){
view.innerHTML="获取验证码";
clearInterval(timer);
bState = true;
}
t--;
},1000);
}
view.onclick=function(){
bState && gain();
}
</script>
</body>
</html>
 演示截图:
 
   | 
 |