来自固定位置的Javascript倒计时脚本

时间:2010-11-21 04:04:29

标签: javascript

我有一个倒计时脚本,倒计时到指定的某一天。我希望它每次加载时都能倒计时24小时,但似乎无法实现它。

感谢

http://pastebin.com/zQ4ESHuG

1 个答案:

答案 0 :(得分:0)

var timeInSecs;
var ticker;

function startTimer(secs){
timeInSecs = parseInt(secs);
ticker = setInterval("tick()",1000);
tick(); // to start counter display right away
}

function tick() {
var secs = timeInSecs;
if (secs>0) {
timeInSecs--;
}
else {
clearInterval(ticker); // stop counting at zero
//startTimer(60 * 60 *24 * 5); // and start again if required
}

var days = Math.floor(secs/86400);
secs %= 86400;
var hours= Math.floor(secs/3600);
secs %= 3600;
var mins = Math.floor(secs/60);
secs %= 60;

var result = ((hours < 10 ) ? "0" : "" ) + hours + ":" + ( (mins < 10) ? "0" : "" ) + mins
+ ":" + ( (secs < 10) ? "0" : "" ) + secs;
result = days + " Days: " + result;
document.getElementById("countdown").innerHTML = result;
}

解决了它。

谢谢大家。