您好我正在尝试将几个 javascript 倒计时添加到单个 html 页面。我在下面包含了 .js 文件。现在我的页面只显示第一个倒计时。
function cdtd () {
var end = new Date("December 25, 2013 00:01:00");
var start = new Date();
var timeDiff = end.getTime() - start.getTime();
if (timeDiff <= 0) {
clearTimeout (timer);
document.write("Deal Ended");
}
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;
document.getElementById("daysBox").innerHTML = days;
document.getElementById("hoursBox").innerHTML = hours;
document.getElementById("minsBox").innerHTML = minutes;
document.getElementById("secsBox").innerHTML = seconds;
var timer = setTimeout('cdtd()',1000);
}
function countdown () {
var end = new Date("May 31, 2013 00:01:00");
var start = new Date();
var timeDiff = end.getTime() - start.getTime();
if (timeDiff <= 0) {
clearTimeout (timer);
document.write("Deal Ended");
}
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;
document.getElementById("daysBox").innerHTML = days;
document.getElementById("hoursBox").innerHTML = hours;
document.getElementById("minsBox").innerHTML = minutes;
document.getElementById("secsBox").innerHTML = seconds;
var timer = setTimeout('countdown()',1000);
}
function cdtd3 () {
var end = new Date("December 25, 2013 00:01:00");
var start = new Date();
var timeDiff = end.getTime() - start.getTime();
if (timeDiff <= 0) {
clearTimeout (timer);
document.write("Deal Ended");
}
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;
document.getElementById("daysBox").innerHTML = days;
document.getElementById("hoursBox").innerHTML = hours;
document.getElementById("minsBox").innerHTML = minutes;
document.getElementById("secsBox").innerHTML = seconds;
var timer = setTimeout('cdtd3()',1000);
}
function cdtd4 () {
var end = new Date("December 25, 2013 00:01:00");
var start = new Date();
var timeDiff = end.getTime() - start.getTime();
if (timeDiff <= 0) {
clearTimeout (timer);
document.write("Deal Ended");
}
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;
document.getElementById("daysBox").innerHTML = days;
document.getElementById("hoursBox").innerHTML = hours;
document.getElementById("minsBox").innerHTML = minutes;
document.getElementById("secsBox").innerHTML = seconds;
var timer = setTimeout('cdtd4()',1000);
}
function cdtd5 () {
var end = new Date("December 25, 2013 00:01:00");
var start = new Date();
var timeDiff = end.getTime() - start.getTime();
if (timeDiff <= 0) {
clearTimeout (timer);
document.write("Deal Ended");
}
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;
document.getElementById("daysBox").innerHTML = days;
document.getElementById("hoursBox").innerHTML = hours;
document.getElementById("minsBox").innerHTML = minutes;
document.getElementById("secsBox").innerHTML = seconds;
var timer = setTimeout('cdtd5()',1000);
}
function cdtd6 () {
var end = new Date("December 25, 2013 00:01:00");
var start = new Date();
var timeDiff = end.getTime() - start.getTime();
if (timeDiff <= 0) {
clearTimeout (timer);
document.write("Deal Ended");
}
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;
document.getElementById("daysBox").innerHTML = days;
document.getElementById("hoursBox").innerHTML = hours;
document.getElementById("minsBox").innerHTML = minutes;
document.getElementById("secsBox").innerHTML = seconds;
var timer = setTimeout('cdtd6()',1000);
}