這裏是我的代碼,其中我使用readCookies函數,但是當它沒有響應時,它在div中什麼也沒有顯示,即使警報也不起作用。我如何避免重置頁面刷新/頁面加載使用Java腳本的計時器值?
seconds = readCookie('countdown') || 60;
alert(seconds);
function secondPassed() {
seconds--;
var minutes = parseInt(seconds/60);
var remainingSeconds = parseInt(seconds % 60);
if (remainingSeconds < 10) {
remainingSeconds = "0" + parseInt(remainingSeconds);
}
document.getElementById('countdown').innerHTML = minutes + " mins : " + remainingSeconds + " secs";
if (parseInt(seconds) === 0) {
alert("Time is over");
clearInterval(countdownTimer);
document.getElementById('countdown').innerHTML = "Time is Over";
document.forms["myForm"].submit();
document.location.href = "examresult.jsp";
}
}
var countdownTimer = setInterval(function() {
secondPassed();
if (seconds === 0) {
eraseCookie(seconds);
} else {
createCookie(seconds, seconds, 7);
}
}, 1000);
設置的定時器秒還餅乾 –