微件:倒计时/js:修订间差异
跳转到导航
跳转到搜索
(导入PRTS模版) |
无编辑摘要 |
||
(未显示2个用户的7个中间版本) | |||
第1行: | 第1行: | ||
<includeonly><script> | <includeonly><script type="text/javascript"> | ||
document. | if(document.readyState == 'interactive' || document.readyState == 'complete') { | ||
// 页面已加载完成 | |||
window.setInterval(CountDownShort, 1000); | |||
} else { | |||
// 没加载完,监听加载完成事件 | |||
document.addEventListener("DOMContentLoaded", function () { | |||
window.setInterval(CountDownShort, 1000); | |||
}); | |||
} | } | ||
function CountDownShort() { | function CountDownShort() { | ||
var a = document.getElementsByClassName("CDScontainer"); | var a = document.getElementsByClassName("CDScontainer"); | ||
第18行: | 第17行: | ||
for (var i = 0; i<a.length; i++) { | for (var i = 0; i<a.length; i++) { | ||
var s = parseInt(a[i].getAttribute("data-time"), 10); | var s = parseInt(a[i].getAttribute("data-time"), 10); | ||
var t = a[i].getAttribute("data-event") || '' | |||
if(t) { | |||
t = '距离'+ t + '还有' | |||
} | |||
if (s > ct) { | if (s > ct) { | ||
var delta = s - ct; | var delta = s - ct; | ||
if (delta > 86400) { | if (delta > 86400) { | ||
t += Math.floor(delta / 86400) + "天"; | t += Math.floor(delta / 86400) + "天"; | ||
第26行: | 第28行: | ||
} | } | ||
if (delta > 3600) { | if (delta > 3600) { | ||
var hour = Math.floor(delta / 3600) | |||
t += (hour < 10 ? '0' + hour : hour) + "时"; | |||
delta = delta % 3600; | delta = delta % 3600; | ||
} | } | ||
if (delta > 60) { | if (delta > 60) { | ||
t += Math.floor(delta | var minute = Math.floor(delta / 60) | ||
t += (minute < 10 ? '0' + minute : minute) + "分"; | |||
delta = delta % 60; | |||
} | |||
if (delta > 0) { | |||
t += (delta < 10 ? "0" : "") + Math.floor(delta) + "秒"; // 添加秒数 | |||
} | } | ||
a[i].innerHTML = t; | a[i].innerHTML = t; | ||
第40行: | 第48行: | ||
} | } | ||
} | } | ||
</script> | </script> | ||
</includeonly><noinclude>{{documentation|content=看[[模板:倒计时/js]]}}</noinclude> | </includeonly> | ||
<noinclude>{{documentation|content=看[[模板:倒计时/js]]}}{{#Widget:倒计时/js}}{{倒计时/js|time=2024-08-20 10:00}}</noinclude> |