gpt4 book ai didi

javascript - 使用 php 的倒计时器来激活按钮点击

转载 作者:行者123 更新时间:2023-11-29 18:23:00 25 4
gpt4 key购买 nike

需要帮助,我的情况是 - 在我的数据库中,我有一个表,其中包含“created_time”列,该表以 HH:MM AM/PM 形式存储当前系统时间。现在我希望一旦在该表中输入当前系统时间的数据,那么在我的 php 页面之一中就会有一个名为“开始考试”的按钮,当前该按钮将处于“禁用”状态,应该完全启用它在数据库中输入时间 1 小时后,倒计时器与按钮一起显示。

谁能帮我解决这个问题。

最佳答案

<script>
var countDownDate = new Date("<?php echo $dateFromDB ?>").getTime();
// Update the count down every 1 second
var x = setInterval(function() {

// Get todays date and time
var now = new Date().getTime();

// Find the distance between now an the count down date
var distance = countDownDate - now;

// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);

// Display the result in the element with id="demo"
document.getElementById("demo").innerHTML = days + "d " + hours + "h "
+ minutes + "m " + seconds + "s ";

// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
// do something when time is expired
}
}, 1000);
</script>

关于javascript - 使用 php 的倒计时器来激活按钮点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46419038/

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