标签:second doc 验证 count inter rac code 计时 scl
<script> var balanceSeconds=getcookie(‘Num‘); console.log(balanceSeconds) var timer; var isClick=true; if(balanceSeconds==‘‘||balanceSeconds==undefined||balanceSeconds==‘120‘){ balanceSeconds=120; isClick=true; $(".getSmsVer_cer").html( "获取验证码"); }else if(0<balanceSeconds<120){ isClick=false; $(".getSmsVer_cer").html(balanceSeconds+ "秒后可重发"); countDownSubtract(); } $(‘.getSmsVer_cer‘).on(‘click‘,function(){ if(isClick){ countDownSubtract(); } }) // 设置cookie function setcookie(name,value,time){ var dates=new Date(); // cookie有效时间120秒 var d=dates.setTime(dates.getTime()+time*(120*1000)); document.cookie=name+‘=‘+value+‘;expires‘+d; } // 获取cookie function getcookie(name){ var b=document.cookie.split("; "); var c=[]; for(var i=0;i< b.length;i++){ c.push(b[i].split("=")); if(name==c[i][0]){ return c[i][1] } } } // 删除cookie function removecookie(name){ setcookie(name,"",-1) } // 120秒倒计时 function countDownSubtract(){ clearInterval(timer); timer = setInterval(countDown, 1000); } function countDown() { if(balanceSeconds > 1){ $(".getSmsVer_cer").html(balanceSeconds + "秒后可重发"); $(".getSmsVer_cer").css("background","#ccc"); isClick=false; } balanceSeconds--; if (balanceSeconds < 1) { $(".getSmsVer_cer").html("现在可重新发送!"); clearInterval(timer); isClick=true; balanceSeconds = 120; $(".getSmsVer_cer").html("获取验证码"); } setcookie(‘Num‘,balanceSeconds,1); } </script>
<div class="getSmsVer_cer">获取验证码</div>
标签:second doc 验证 count inter rac code 计时 scl
原文地址:http://www.cnblogs.com/En-summerGarden/p/7802861.html