1
如何將當前計時器的計時傳遞到下一頁?將當前計時器的計時傳遞到下一頁
定時器代碼
var expires = new Date();
expires.setSeconds(expires.getSeconds() + 60); // set timer to 60 seconds
var counter = setInterval(timer, 1);
function timer() {
var timeDiff = expires - new Date();
if (timeDiff <= 0) {
clearInterval(counter);
document.getElementById("timer").innerHTML = "00:00";
return;
}
var seconds = new Date(timeDiff).getSeconds();
var milliSeconds = (new Date(timeDiff).getMilliseconds()/10).toFixed(0);
var seconds = seconds < 10 ? "0" + seconds: seconds;
var milliSeconds = milliSeconds < 10 ? "0" + milliSeconds: milliSeconds;
document.getElementById("timer").innerHTML = seconds + ":" + milliSeconds; // watch for spelling
}
我在我的HTML中使用
<h3 style="color: #ff0000; margin: 0; padding: 0; font-size: 100%;font-weight:normal; font-family: robotolight;"> You have <div id="timer"></div> to complete the game!
。
有沒有辦法將div id ='timer'>傳入下一頁?
謝謝。
是的,使用cookies或localStorage – hindmost 2014-10-18 09:11:55
localStorage.setItem('timer','timerpage1'); 這是存儲計時器數據的正確方法嗎? – User358218 2014-10-18 09:15:01