`
annan211
  • 浏览: 445539 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

js 获取验证码倒计时

 
阅读更多
点击通过手机或邮箱获取验证码,点击之后进入手机验证码或者邮箱验证码获得的页面,验证码已经发出。需要在页面上出现倒计时,可参照如下代码。
  var wait=60;
	var logNum = Math.floor(Math.random() * 60 + 1);
	function time(o,num) {
			if (wait == 0) {
				o.removeAttribute("disabled");			
				o.value="再次免费获取验证码";
				wait = 60;
			} else {
				o.setAttribute("disabled", true);
				o.value="重新发送(" + wait + ")";
				if(wait==logNum){
					resend();
				}
				wait--;
				setTimeout(function() {time(o,wait);},1000);
			}
		}
	document.getElementById("btn").onclick=function(){time(this,null);}
	
	var maxtime = 60; 
	function CountDown(){  
		if(maxtime>=0){  
				document.all["btn"].setAttribute("disabled", true);
				seconds = Math.floor(maxtime%60);
				msg = "重新发送("+seconds+")";  
				document.all["btn"].value = msg;  
				--maxtime;  
		}  
		else{  
				clearInterval(timer); 
				msg = "重新发送";
				document.all["btn"].value = msg; 
				document.all["btn"].removeAttribute("disabled");
			}  
		}  
	timer = setInterval("CountDown()",1000); 
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics