0
這是倒數計時器倒數計時器應繼續兩個PHP頁面
<script language="JavaScript">
<!--
var hoursleft = 0;
var minutesleft = 10; // you can change these values to any value greater than 0
var secondsleft = 0;
var millisecondsleft = 0;
var finishedtext = "Countdown finished!" // text that appears when the countdown reaches 0
end = new Date();
end.setMinutes(end.getMinutes()+minutesleft);
end.setSeconds(end.getSeconds()+secondsleft);
end.setMilliseconds(end.getMilliseconds()+millisecondsleft);
function cd(){
now = new Date();
diff = end - now;
diff = new Date(diff);
var msec = diff.getMilliseconds();
var sec = diff.getSeconds();
var min = diff.getMinutes();
if (min < 10){
min = "0" + min;
}
if (sec < 10){
sec = "0" + sec;
}
if(msec < 10){
msec = "00" +msec;
}
else if(msec < 100){
msec = "0" +msec;
}
if(now >= end){
clearTimeout(timerID);
document.getElementById("cdtime").innerHTML = finishedtext;
}
else{
document.getElementById("cdtime").innerHTML = min + ":" + sec + ":" + msec;
} // you can leave out the + ":" + msec if you want...
// If you do so, you should also change setTimeout to setTimeout("cd()",1000)
timerID = setTimeout("cd()", 10);
}
window.onload = cd;
//-->
</script>
我想這個計時器將持續兩個PHP頁面,而無需再次重新啓動代碼。當每個問題顯示時,定時器不應該重新啓動。 test1.php頁面有全部的選擇題答案和test2.php頁面都有填空題答案。在我的應用程序中,首先運行test1.php(即MCQ),然後運行所有MCQ test2.php。我怎樣才能爲這兩個頁面使用相同的計時器。
看看Java腳本'localStorage'或在PHP會議 – Nano
嘗試粘貼定時器的HTML代碼。在PHP文件,並把這個腳本在name.js一個文件,然後它包含兩個文件英寸 –
@anant我做了你所說的但仍然計時器重新開始 –