当那部分没有任何内容时,我想让这个 JavaScript 倒数计时器显示 01 而不是 1 和 00。我基本上只是想让它看起来像一个数字时钟,但是当没有 0 使它挤进去时它看起来很奇怪。
这是我找到的脚本:
// JavaScript Document
CountDownTimer('03/25/2013 9:0 AM', 'countdownSpring');
CountDownTimer('06/10/2013 9:0 AM', 'countdownSummer');
CountDownTimer('11/27/2013 9:0 AM', 'countdownFall');
CountDownTimer('12/23/2013 9:0 AM', 'countdownWinter');
function CountDownTimer(dt, id)
{
var end = new Date(dt);
var _second = 1000;
var _minute = _second * 60;
var _hour = _minute * 60;
var _day = _hour * 24;
var timer;
function showRemaining() {
var now = new Date();
var distance = end - now;
if (distance < 0) {
clearInterval(timer);
document.getElementById(id).innerHTML = 'CAMP IS HERE!';
return;
}
var days = Math.floor(distance / _day);
var hours = Math.floor((distance % _day) / _hour);
var minutes = Math.floor((distance % _hour) / _minute);
var seconds = Math.floor((distance % _minute) / _second);
document.getElementById(id).innerHTML = days + ':';
document.getElementById(id).innerHTML += hours + ':';
document.getElementById(id).innerHTML += minutes + ':';
document.getElementById(id).innerHTML += seconds;
}
timer = setInterval(showRemaining, 1000);
}