admin 发表于 2014-9-20 18:32:16

原生JS:获取验证码间隔

原生JS:获取验证码间隔

<!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>

演示截图:
页: [1]
查看完整版本: 原生JS:获取验证码间隔