星空网 > 软件开发 > Java

可以防止刷新重置的倒计时实例代码

可以防止刷新重置的倒计时实例代码:
一般说来,除了我们明确设置一个到期时间日期,比如类似于2018-5-12这样,一般在刷新网页的时候都会使倒计时重新来过,下面就介绍一下可以防止这种情况的方式,希望能够给需要的朋友带来一定的帮助。
实例代码如下:

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>window对象的name属性-蚂蚁部落</title></head> <body> <script type="text/javascript"> var maxtime; if(window.name==''){   maxtime=7*60; }else{  maxtime=window.name; } function CountDown(){  if(maxtime>=0){   minutes=Math.floor(maxtime/60);   seconds=Math.floor(maxtime%60);   msg="距离倒计时结束还有:"+minutes+"分"+seconds+"秒";   document.all["timer"].innerHTML=msg;   if(maxtime==5*60){   alert('距离结束还是有五分钟');   }   --maxtime;   window.name=maxtime;   }  else{   clearInterval(timer);   alert("倒计时已经结束了");  } } timer=setInterval("CountDown()",1000); </script> <div id="timer"></div>  </body> </html>

以上代码实现了我们的要求,尽管刷新页面也会被时倒计时效果重置。之所以能够实现这样的效果,是因为window.name属性值,在刷新网页的时候是不会改变的,甚至页面加载了其他域名的页面也不会改变。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=9088

更多内容可以参阅:http://www.softwhy.com/javascript/




原标题:可以防止刷新重置的倒计时实例代码

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

德国dpd国际快递官网:https://www.goluckyvip.com/tag/100520.html
澳洲珀斯国际快递:https://www.goluckyvip.com/tag/100521.html
如何发国际快运:https://www.goluckyvip.com/tag/100522.html
国际快递可以寄液体:https://www.goluckyvip.com/tag/100523.html
ems国际快递收费:https://www.goluckyvip.com/tag/100524.html
购买国际快递:https://www.goluckyvip.com/tag/100525.html
去日本入住酒店,东西随意用却有一个特殊“要:https://www.vstour.cn/a/411241.html
中国有哪些著名的酒店品牌。:https://www.vstour.cn/a/411242.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流