我正在使用JavaScript Timer來製作測驗系統,它使用會話開始時間來計算定時器工作所需的時間。它在一些系統上工作正常,但不是全部。
可以請一些幫助我..?JavaScript定時器:使用會話開始時間不工作
var ct = setInterval("calculate_time()",100); // Start clock.
function calculate_time()
{
var end_time = "<?php echo $_SESSION['start_time']; ?>"; // Get end time from session variable (total time in seconds).
var dt = new Date(); // Create date object.
var time_stamp = dt.getTime()/1000; // Get current minutes (converted to seconds).
var total_time = end_time - Math.round(time_stamp); // Subtract current seconds from total seconds to get seconds remaining.
var mins = Math.floor(total_time/60); // Extract minutes from seconds remaining.
var secs = total_time - (mins * 60); // Extract remainder seconds if any.
if(secs < 10){secs = "0" + secs;} // Check if seconds are less than 10 and add a 0 in front.
document.getElementById("txt").value = mins + ":" + secs; // Display remaining minutes and seconds.
// Check for end of time, stop clock and display message.
if(mins <= 0)
{
if(secs <= 0 || mins < 0)
{
clearInterval(ct);
document.getElementById("txt").value = "0:00";
var form = document.createElement("form");
form.action = "http://www.example.org/q/conflinux/expire_me.php";
form.method = "post"
document.body.appendChild(form);
form.submit();
}
}
}
.....
.....
<form> <input id="txt" readonly> </input></form>
此外,包括這是不工作的瀏覽器。 –
刪除這些「引號」 ct = setInterval(「calculate_time()」,100); –
已經在我的回答和他的新代碼 – mplungjan