当我的计时器转到00:00:00时,下一秒将像23:59:59一样继续倒计时。如何在00:00:00停止计时器,或者当计时器= 00:00:00自动点击按钮时停止按钮<input type=submit name=submit value='Get Result' id='submitpaper'>展示<div id=response class=timer style=font-size:30px></div>这是First.php$duration=$row["duration"];$_SESSION["duration"]=$duration;$_SESSION["start_time"]=date("Y-m-d H:i:s");$end_time=$end_time=date('Y-m-d H:i:s', strtotime('+'.$_SESSION["duration"].'minutes',strtotime($_SESSION["start_time"])));$_SESSION["end_time"]=$end_time;?>这是我的response.php<?phpsession_start();$from_time1=date('Y-m-d H:i:s');$to_time1=$_SESSION["end_time"];$timefirst=strtotime($from_time1);$timesecond=strtotime($to_time1);$differenceinseconds=$timesecond-$timefirst;echo gmdate("H:i:s",$differenceinseconds);?>JavaScript位于时间显示页面的位置。 var x = setInterval(test,1000); function test(){ var xmlhttp=new XMLHttpRequest(); xmlhttp.open("GET","response.php",false); xmlhttp.send(null); document.getElementById("response").innerHTML=xmlhttp.responseText;}
1 回答
一只萌萌小番薯
TA贡献1795条经验 获得超7个赞
您可以将响应php编辑为
<?php
session_start();
$from_time1=date('Y-m-d H:i:s');
$to_time1=$_SESSION["end_time"];
$timefirst=strtotime($from_time1);
$timesecond=strtotime($to_time1);
$differenceinseconds=$timesecond-$timefirst;
//if countdown smaller than 0, countdown should be 0
if($differenceinseconds<0)$differenceinseconds=0;
echo gmdate("H:i:s",$differenceinseconds);
?>
添加回答
举报
0/150
提交
取消