我正在尝试学习一些 java 脚本来做一个工作面试评估项目。问题是我有一个计时器,当计时器达到零时,它应该用另一个包含文本和图像的 div 替换包含它的 div。我搜索但找不到这样的例子。这是计时器的代码,我想我应该在 clearTimeout 之后放一些东西,但是我尝试的一切都不起作用:
function cdtd() {
var kickoff = new Date("June 07, 2013 20:13:00");
var now = new Date();
var timeDiff = kickoff.getTime() - now.getTime();
if (timeDiff <= 0) {
clearTimeout ("timer");
}
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %=24;
minutes %=60;
seconds %= 60;
if (seconds < 10) {
seconds = "0" + seconds;
}
if (minutes < 10) {
minutes = "0" + minutes;
}
if (hours < 10) {
hours = "0" + hours;
}
if (days < 10) {
days = "0" + days;
}
document.getElementById("daysBox").innerHTML = days;
document.getElementById("hoursBox").innerHTML = hours;
document.getElementById("minsBox").innerHTML = minutes;
document.getElementById("secondsBox").innerHTML = seconds;
var timer = setTimeout('cdtd()',1000);
}