本文实例讲述了JavaScript实现的商品抢购倒计时功能。分享给大家供大家参考,具体如下:
<html> <head> <meta charset="utf-8"> <title>JS抢购倒计时</title> </head> <body> <span id="times" > <SCRIPT LANGUAGE="JavaScript"> function _fresh() { var endtime=new Date("2017/4/23,19:33:12"); var nowtime = new Date(); var leftsecond=parseInt((endtime.getTime()-nowtime.getTime())/1000); __d=parseInt(leftsecond/3600/24); __h=parseInt((leftsecond/3600)%24); __m=parseInt((leftsecond/60)%60); __s=parseInt(leftsecond%60); var c=new Date(); var q=((c.getMilliseconds())%10); document.getElementById("times").innerHTML=__d+"天 "+__h+"小时"+__m+"分"+__s+"."+q+"秒"; if(leftsecond<=0){ document.getElementById("times").innerHTML="抢购已结束"; clearInterval(sh); } } _fresh() var sh; sh=setInterval(_fresh,100); </SCRIPT> </span> </body> </html>
运行效果图如下:
- 看不过瘾?点击下面链接!
- win10系统自带Wifi如何开启
- Win10 Build 15063.138更新了什么
- Win10创意者更新不显示文字怎么解决
- Windows10创意者更新值不值得升级
- Win10火狐浏览器无法使用迅雷xz怎么办
- Win10笔记本玩游戏不能全屏怎么办