实用短信验证码倒计时判断,专为广大新手准备,此函数可以有效避免应用回到桌面导致验证码重新计算
无
<div style="width:90%; height:auto; float:left; padding: 0px 15px; margin-top:10px;">
<input style="width:200px; height:40px; min-height:40px; line-height:40px; float:left; border:1px solid #efefef;" />
<a id="GetCode" style="width:100px;height:40px; float:right; line-height:40px; background: #F37668; border-radius: 5px; text-align: center; font-size:14px; color: #fff;">获取验证码</a>
</div>
</body>
<script type="text/javascript">
$api.addEvt($api.dom('#GetCode'), 'click',function(){
get_auth_code('#GetCode',Date.now());
});
function get_auth_code(el,getCodeTime){
if(Date.now()-getCodeTime<60000){
$api.html($api.dom(el),'重新获取('+Math.ceil( (getCodeTime/1+60000-Date.now())/1000 )+'s)');
$apiutil.css($api.dom(el),'pointer-events:none;color:#fff;background: #ccc;');
setTimeout(function(){get_auth_code(el,getCodeTime)},1000);
}else{
$api.html($api.dom(el),'获取验证码');
$apiutil.css($api.dom(el),'pointer-events:auto;color:#fff;background: #F37668;');
}
};
</script>
无