我需要制作一个倒计时计时器,该计时器在时间过去后自动重新启动。
例如,我需要从英国时间下午 3 点或 15:00 开始倒计时,并在时间到时重新开始计数。
我一直在尝试使用一些 jQuery,但这会显示浏览器时间而不是服务器时间。如果有人能够分享解决方案,请告诉我。
提前致谢!
下面的代码是一个完美的工作示例:https ://gist.github.com/Majestik/3964527
if (document.getElementById('countdownTimer')) {
pad = function(n, len) { // leading 0's
var s = n.toString();
return (new Array( (len - s.length + 1) ).join('0')) + s;
};
function countDown() {
var now = new Date();
if ( (now.getDay() >= 1) && (now.getDay() <= 5) ) { // Monday to Friday only
var target = 15; // 15:00hrs is the cut-off point
if (now.getHours() < target) { // don't do anything if we're past the cut-off point
var hrs = (target - 1) - now.getHours();
if (hrs < 0) hrs = 0;
var mins = 59 - now.getMinutes();
if (mins < 0) mins = 0;
var secs = 59 - now.getSeconds();
if (secs < 0) secs = 0;
var str = pad(hrs, 2) + ':' + pad(mins, 2) + '.<small>' + pad(secs, 2) + '</small>';
document.getElementById('countdownTimer').innerHTML = str;
}
}
}
var timerRunning = setInterval('countDown()', 1000);
}
Time remaining: <span id="countdownTimer"><span>00:00.<small>00</small></span>