我在新的JavaScript,我想創建一個的localStorage倒數計時器,從給定的時間開始和結束00:00:00,但它不工作, 當我跑我的代碼顯示值「1506」。倒數計時器沒有在JavaScript顯示
這裏是我的代碼
<script type="text/javascript">
if (localStorage.getItem("counter")) {
var CurrentTime = localStorage.getItem("counter");
}
else {
var Hour = 3;
var Minute = 25;
var Second = 60;
var CurrentTime = Hour.toString() + ":" + Minute.toString() + ":" + Second.toString();
}
function CountDown() {
document.getElementById('lblDuration').innerHTML = CurrentTime;
Second--;
if (Second == -1) {
Second = 59;
Minute--;
}
if (Minute == -1) {
Minute = 59;
Hour--;
}
localStorage.setItem("counter", CurrentTime);
}
var interval = setInterval(function() { CountDown(); }, 1000);
</script>
你從來沒有修改CURRENTTIME在你的函數'COUNTDOWN()'。 –
嗨@Gerald Schneider 感謝您的評論,我不明白,請你解釋一下嗎? –