倒计时

xiaoxiao2021-02-28  4

<!DOCTYPE html> <html> <head> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript"> var countdown=60; function settime(obj) { if (countdown == 0) { obj.removeAttribute("disabled"); obj.value="免费获取验证码"; countdown = 60; return; } else { obj.setAttribute("disabled", true); obj.value="重新发送(" + countdown + ")"; countdown--; } setTimeout(function() { settime(obj) } ,1000) } </script> <body> <input type="button" id="btn" value="免费获取验证码" οnclick="settime(this)" /> </body> </html> -------------------------------经验-----------------------注意;写成setTimeout("RemainTime(),1000)"调用不了! -------------------------------------------------------------function getcode(){ var telphone = $("#username").val(); $.ajax({ type:"POST", url:"/index.php/Public/sendcode/", dataType:"json", data:{telphone:telphone}, success:function(data){ //判断是否发送成功! if(data.errno==0) { alert(data.errdesc); RemainTime(); } else { alert(data.errdesc); return false; } } }) } var iTime = 59; var Account; function RemainTime(){ $('#get_code').attr('disabled',false); var iSecond,sSecond="",sTime=""; if (iTime >= 0){ iSecond = parseInt(iTime`); iMinute = parseInt(iTime/60) if (iSecond >= 0){ if(iMinute>0){ sSecond = iMinute + "分" + iSecond + "秒"; }else{ sSecond = iSecond + "秒"; } } sTime = sSecond; if(iTime==0){ clearTimeout(Account); sTime='获取手机验证码'; iTime = 59; $('#get_code').attr('disabled',false); }else{ iTime=iTime-1; Account = setTimeout(function(){RemainTime()},1000);//注意;写成setTimeout("RemainTime(),1000)"调用不了! //alert(Account); } }else{ sTime='没有倒计时'; } $('#get_code').html(sTime); } $("#register_btn").on('click',func); $("#get_code").on('click',getcode);  
转载请注明原文地址: https://www.6miu.com/read-1100191.html

最新回复(0)