好的,你可以從這篇文章的標題中得知。我正在嘗試如何創建一個24小時剩餘的倒數時鐘。我無法理解如何解決這個問題。設置24小時剩餘倒計時
我知道了,5分鐘工作,但我只需要在如何把它變成小時,而不是
HTML的在正確的方向輕推:
<body>
<input type="text" value="5">
<div>Time Remaining <span id="remainingTime">05:00</span> minutes!</div>
</body>
JavaScript/jQuery:
function Timer(duration, display)
{
var timer = duration, minutes, seconds;
setInterval(function() {
minutes = parseInt(timer/60, 10)
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.text(minutes + ":" + seconds);
if (--timer < 0) {
timer = duration;
}
}, 1000);
}
jQuery(function ($)
{
var fiveMinutes = 60 * jQuery('#checkTime').val();
var display = $('#remainingTime');
Timer(fiveMinutes, display);
});
請插件。
這已經說過一千次,我知道,但爲什麼不能用一個簡單的jQuery插件呢?特別是因爲你已經加載jQuery的依賴。或者這是一個學習如何構建計時器的寵物項目? –
@JonKoops - 這是一個寵物項目,我不想使用jQuery插件 –
@JonKoops我可能對此很蠢,答案是60 * 60 *任何數字在輸入字段中? –