【发布时间】:2012-04-02 15:18:15
【问题描述】:
我有一个倒数计时器,它使用此脚本将时间从 H:i:s 传输到长版本:
function parseTime() {
var timeLeftStr;
var timeLeft = 0;
timeLeftStr = document.getElementById("timeleft").innerHTML;
timeLeftStr.replace(/(\d+):(\d+):(\d+)/, function () {
for (var i = 1; i < arguments.length - 2; i++) {
// Convert to ms
timeLeft += arguments[i] * Math.pow(60, 3 - i) * 1000;
}
});
countdown(new Date(timeLeft));
}
function countdown(timeLeft) {
var hours = timeLeft.getHours();
var minutes = timeLeft.getMinutes();
var seconds = timeLeft.getSeconds();
if (timeLeft.valueOf() == 0) {
document.getElementById("timeleft").innerHTML = "0 seconds";
window.location = 'home.php?pageid=' + getURLParam("pageid");
return false;
} else {
document.getElementById("timeleft").innerHTML =
(hours == 0 ? "" : hours + (hours == 1 ? " hour" : " hours")) +
(minutes == 0 ? "" : (hours ? (seconds ? ", " : " and ") : " ") + minutes + (minutes == 1 ? " minute" : " minutes")) +
(seconds == 0 ? "" : (hours || minutes ? " and " : "") + seconds + (seconds == 1 ? " second" : " seconds"));
setTimeout(function () { countdown(new Date(timeLeft - 1000)); }, 1000);
}
}
window.onload = parseTime;
错误是我的一个居住在澳大利亚的用户不断输入错误的“小时” 最初的计时器会说“23:45:05”,但是当倒数计时器启动时,它会说“10 小时 45 分 5 秒”而不是 23 小时。
知道为什么会发生这种情况吗?谢谢。
我不擅长 JS,这是一个朋友创建的。
最终解决了。
【问题讨论】:
标签: php javascript