当前位置: 代码迷 >> PHP >> php+js 倒计时 几秒之后 不动了解决方法
  详细解决方案

php+js 倒计时 几秒之后 不动了解决方法

热度:334   发布时间:2016-04-29 00:55:28.0
php+js 倒计时 几秒之后 不动了
之前弄了一个倒计时代码 有两个问题
1. 刷新之后 倒计时还是挺顺的 但是等个半分钟,倒计时就开始卡 然后就不动了,这是为什么?
2. 卡了之后再点刷新,网页没反应,除非把这个页面关了 重新打开,然后重复第一个问题。。

代码如下:
PHP code
<script language="JavaScript">function getTheTime(D,i){     var theDate=new Date(D);     var date = new Date();     var diffTime = theDate - date;     //if(diffTime<=0){      //document.getElementById("diffDay2"+i) .innerHTML="时间已过.";      //return;     //}     var para = 1000 * 60 * 60 * 24;     var diffday = diffTime / para;     var diffHour = (diffTime % para) / 3600000;     var diffMinute = (diffTime % 3600000 ) / 60000;     var diffSecond = (diffTime % 60000) / 1000;     //document.getElementById("diffDay1"+i).innerHTML = "<b>"+Math.floor(diffday)+ "</b>" + "天 ";     document.getElementById("h_diffDay2"+i).innerHTML = Math.floor(diffHour);     document.getElementById("m_diffDay2"+i).innerHTML = Math.floor(diffMinute);     document.getElementById("s_diffDay2"+i).innerHTML = Math.floor(diffSecond);               setInterval("getTheTime('" + D + "'," + i + ")", 1000); }</javascript><table style="width:80%; margin:auto" border="0"><tr><td class="txt_d_cd" style="color:#d34836">Deadline</td><td class="txt_d_cd" colspan="3">Countdown For <strong style="color:#d34836">Dinner</strong></td></tr><?php$query="SELECT * FROM PICKUPTIME ORDER BY deadline ASC";$sql=queryMysql($query);$i=0;while($info=mysql_fetch_array($sql)){    $deadline_dinner=$info['deadline'];    if($info['deadline'] == "") continue;    //echo $info['deadline'];    $time_hr=substr($deadline_dinner, 0, 2);    $time_min=substr($deadline_dinner, 2, 4);    $pickup_time_formatted=$time_hr.":".$time_min;    //$c_date=date("Y-m-d");    $deadline=date("Y-m-d")." "."$pickup_time_formatted";    $current_time=date("Y-m-d H:i:s");    if($deadline<$current_time)    {        $deadline=date("Y-m-d", strtotime('+1 day'))." "."$pickup_time_formatted";        $dinner_notice="TOMORROW";    }    else    {        $dinner_notice="TODAY";    }    //echo "$deadline";?>                <tr>                    <td class="txt_d_cd"><?php echo "$dinner_notice $pickup_time_formatted"; ?></td>                    <td class="txt_cd"><strong id="h_diffDay2<?php echo $i;?>"></strong>h</td>                    <td class="txt_cd"><strong id="m_diffDay2<?php echo $i;?>"></strong>m</td>                    <td class="txt_cd"><strong id="s_diffDay2<?php echo $i;?>"></strong>s</td>                </tr>                                <script type="text/javascript">                        getTheTime("<?php echo $deadline;?>",<?php echo $i;?>);                    </script> <?php    $i++;}?> </table>


------解决方案--------------------
我之前做过类似东西,好像还可以搜索到
  相关解决方案