我需要幫助。 我正在爲我的遊戲網站製作一個倒計時腳本,該腳本抓取數據庫的結束時間並倒計時,直到當前時間等於數據庫時間。 但我似乎無法讓它停止,當它達到0. 我已經看着setTimeout(),我不明白我如何得到這個工作。停止jquery計時器,當它達到0
此外,當頁面刷新時,它會從數據庫時間再次啓動計時器。我怎麼會更新數據庫到剩下的時間或停止刷新計時器。
非常感謝。下面是劇本我到目前爲止
<?php
include "header.php";
?>
<html>
<head>
<script type="text/javascript">
var curTime = Math.floor((new Date()).getTime()/1000); // replaced with PHP time(), presumably
var endTime = Math.floor((new Date()).getTime()/1000) + <?php echo $user_class->jail;?>;
function tick()
{
var secs = endTime - cTime;
var mins = Math.floor(secs/60);
secs %= 60;
document.getElementById("ticker").innerHTML =
mins + " minutes, " + secs + " seconds";
++curTime;
}
</script>
</head>
<body onload="setInterval(tick,1000); tick();">
<h3>Time remaining is <span id="ticker"></span></h3>
</body>
</html>
我的數據庫通過cron目前更新每隔1分鐘,因此能進能出,由於cron的。但我想知道是否有辦法通過倒數來更新數據庫,所以它會像其他定時器一樣精確。
clearInterval()? – Robert 2015-02-24 16:01:22