查看: 509|回复: 0

[JavaScript/JQuery] 限时抢购-倒计时

发表于 2017-10-7 08:42:37
尚学堂AD
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset=utf-8"/>
  5. <title>团购——限时抢</title>
  6. </head>
  7. <body>
  8. <div>
  9. <div class="time">还剩 <span id="LeftTime"></span></div>
  10. </div>
  11. <script>
  12. function FreshTime() {
  13. var endtime = new Date("2017/10/15,12:20:12");//结束时间
  14. var nowtime = new Date();//当前时间
  15. var lefttime = parseInt((endtime.getTime() - nowtime.getTime()) / 1000);
  16. d = parseInt(lefttime / (24 * 3600));
  17. h = parseInt(lefttime /3600%24);
  18. m = parseInt(lefttime/60%60);
  19. s = parseInt(lefttime % 60);
  20. document.getElementById("LeftTime").innerHTML = d + "天" + h + "小时" + m + "分" + s + "秒";
  21. if (lefttime <= 0) {
  22. document.getElementById("LeftTime").innerHTML = "团购已结束";
  23. clearInterval(sh);
  24. }
  25. }
  26. var sh;
  27. sh = setInterval(function () {
  28. FreshTime()
  29. },500);
  30. </script><br>
  31. </body>
  32. </html>
复制代码

效果图:



回复

使用道具 举报