我試圖從數據庫創建倒計時器。我已將deltaTimeServer發送給JS。輸出是正確的,但他們凍結(不倒計時,我必須按F5)。對我有什麼想法?從mysql的倒計時器定時器
這是我的代碼。
JS
<script type="text/javascript">
function countDown(){
$(".show").each(function() {
var elm = $(this);
var difTime=this.timestamp;
var day=0,hours=0,minutes=0,seconds=0;
if(difTime>0){
day=Math.floor(difTime/84600);
hours=(Math.floor((difTime/3600))%24) + day*24 ;
minutes=Math.floor(difTime/60)%60;
seconds=Math.floor(difTime)%60;
}
else{
elm.removeClass("show"); //for remove class show
}
elm.html(hours+' H '+minutes+' M '+seconds+' S ');
});
}
function countDown_onLoad(){
$(".show").each(function() {
this.timestamp = parseInt(this.firstChild.nodeValue,10);
});
setInterval(countDown,1000);
}
$(document).ready(function() {
countDown_onLoad();
});
</script>
PHP
$show=mysql_query("SELECT * FROM `room_lists` WHERE `active` = 1");
while ($array = mysql_fetch_array($show))
{
$timeStop = $array['timeStop'];
$deltaTimeServer = strtotime($timeStop)-strtotime(date('Y-m-d H:i:s'));
echo "<td align = 'center'><div class=\"show\">".$deltaTimeServer."</div></td>";
}
檢查您的瀏覽器控制檯,可能是一個流氓例外拋出'setInterval' – nbaztec 2012-08-10 06:59:49