首页 > 编程 > JavaScript > 正文

js倒计时显示实例

2019-11-19 18:34:32
字体:
来源:转载
供稿:网友

话不多说,请看实例代码

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>js倒计时显示-细数逝去的过往</title><style type="text/css">#clock {font: bold 24pt sans;background-color: #f5f5f5;padding: 10px 15px;border: 1px solid #ccc;border-radius: 5px;}.demo {position: absolute;margin-left: 40%;margin-top: 40%;}</style></head><body><div class="demo"><center><h1>下班倒计时显示</h1></center><span id="clock"></span></div><script>function displayTime() {var elt = document.getElementById("clock");if(leftTime < 0) {elt.innerHTML = "Over";} else {var endTime = new Date("2016/11/21 18:00:00");var now = new Date();var leftTime = endTime.getTime() - now.getTime();var ms = parseInt(leftTime % 1000).toString();leftTime = parseInt(leftTime / 1000);var o = Math.floor(leftTime / 3600);var d = Math.floor(o / 24);var m = Math.floor(leftTime / 60 % 60);var s = leftTime % 60;elt.innerHTML = o + "小时:" + m + "分:" + s + "秒:" + ms.charAt(0);setTimeout(displayTime, 100);}}displayTime();</script></body></html>

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持武林网!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表