我有一个倒计时脚本,但我有 2 个问题。1. 我的倒计时永远不会达到 0 并停止,所以我得到一个连续的负数。2. 计数器只显示 chrome 而不是 firefox 或 internet explorer。如何解决这两个问题?
var sec, min, hr, day, timer, expireDate;
sec = 1000;
min = 60 * 1000;
hr = 60 * 60 * 1000;
day = 24 * 60 * 60 * 1000;
timer;
expireDate = new Date('Mon Sep 17 2012 14:26:00 GMT-0700');
timer = setInterval(function() {
var currentDate, countdown, days, hours, minutes, seconds;
currentDate = new Date();
countdown = expireDate - currentDate;
if (countdown === 0 ) {
window.clearInterval(timer);
document.getElementById('countdown').innerHTML = 'EXPIRED!';
}
days = Math.floor(countdown / day);
hours = Math.floor((countdown % day) / hr);
minutes = Math.floor((countdown % hr) / min);
seconds = Math.floor((countdown % min) / sec);
console.log(countdown);
document.getElementById('countdown').innerHTML = days + " " + hours + " " + minutes + " " + seconds;
}, 1000);