var maxtime; if(window.name==''){ maxtime = 2*60; }else{ maxtime = window.name; } function CountDown(){ if(maxtime>0){ $("#resetMsg").text("重发("+maxtime+"S)").attr("disabled",true); --maxtime; window.name = maxtime; } else{ clearInterval(timer); $("#resetMsg").text("重发").removeClass("layui-btn-disabled").attr("disabled",false); } } timer = setInterval("CountDown()",1000); function CountDowns(){ maxtime = 2*60; if(maxtime>0){ $("#resetMsg").text("重发("+maxtime+"S)").addClass("layui-btn-disabled").attr("disabled",true); --maxtime; window.name = maxtime; } else{ clearInterval(timers); $("#resetMsg").text("重发").removeClass("layui-btn-disabled").attr("disabled",false); } timers = setInterval("CountDown()",1000); } $(".retext-code").on('click',function(){ var _this = $(this); CountDowns(); var mobile = $("#mobile").val(); var securitycode = $("#securitycode").val(); $.post("<?=getUrl('customer/Register/step2')?>",{mobile:mobile,securitycode:securitycode,reSend:1},function(data,status){ if(data.code==1){ layer.msg(data.msg); clearInterval(timers); _this.removeClass("layui-btn-disabled").attr("disabled",false); maxtime = -1; _this.text("重发") }else{ layer.msg(data.msg); } }) }) 用window.name保存时间,现在是可以防刷新了,但是新的问题是,只要不关闭该窗口, 在倒计时没有结束的时候再次进入该页面,还是会接着上次的没有结束的倒计时开始计算。 求大神帮助哇~~~
FSYu
相关分类