gpt4 book ai didi

javascript - 如何设置倒计时器停止在 00 :00:00 OR when =0 auto click button

转载 作者:行者123 更新时间:2023-12-02 23:43:24 25 4
gpt4 key购买 nike

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

这是第一个.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;
}

最佳答案

您可以将响应 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);

?>

关于javascript - 如何设置倒计时器停止在 00 :00:00 OR when =0 auto click button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55963399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com