猿问

如何设置倒数计时器在00:00:00停止或在= 0自动点击按钮时停止

当我的计时器转到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


<?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;

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;

}


慕雪6442864
浏览 263回答 1
1回答

一只萌萌小番薯

您可以将响应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;//if countdown smaller than 0, countdown should be 0if($differenceinseconds<0)$differenceinseconds=0;echo gmdate("H:i:s",$differenceinseconds);?>
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答