首页 > 后端开发 > php教程 > php+js倒计时代码 秒不动解决思路

php+js倒计时代码 秒不动解决思路

WBOY
发布: 2016-06-13 13:27:41
原创
742 人浏览过

php+js倒计时代码 秒不动
从网上找的这段代码 运行之后 秒 是不动的 为什么?

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<script type="text/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)+ "" + "天 ";
     document.getElementById("diffDay2"+i).innerHTML = Math.floor(diffHour) + "小时" + Math.floor(diffMinute) + "分" + Math.floor(diffSecond) + "秒";
     setTimeout("getTheTime("+D+","+i+")",1000);     
     //document.getElementById("test_date").innerHTML = theDate;
     //document.getElementById("test_date_1").innerHTML = date;
}
</script> 
<?php include_once '../lib/functions.php';
$db = new Connection();
$connection = $db->connect();

$query="SELECT * FROM PICKUPTIME ORDER BY deadline ASC";
$sql=queryMysql($query);
?>
<?php $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";
    //echo "$deadline";

?>
<div id="test_date"></div>

    <div style="float:left;" id="test_date"></div>
    <div style="float:left;" id="test_date_1"></div>
    
    <div style="float:left;" id="diffDay1<?php echo $i;?>"></div>
    <div  id="diffDay2<?php echo $i;?>"></div>
    <script type="text/javascript">
    getTheTime("<?php echo $deadline;?>",<?php echo $i;?>);
    </script> 
<?php $i++;
}
?> 


登录后复制


------解决方案--------------------
JScript code
//setTimeout("getTheTime("+D+","+i+")",1000);
setInterval("getTheTime('" + D + "'," + i + ")", 1000); <div class="clear">
                 
              
              
        
            </div>
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板