倒数计时器使用PHP来激活按钮点击
问题描述:
需要帮助guyz,我的场景是 - 在我的数据库中,我有一个列“created_time”,它将当前系统时间存储在HH:MM AM/PM中。现在我希望只要当前系统时间在表中输入数据,然后在我的一个php页面中就会有一个名为“开始考试”的按钮,目前该按钮将处于“禁用”状态,应该正确启用它在输入数据库1小时后,随着按钮显示倒数计时器。倒数计时器使用PHP来激活按钮点击
任何人都可以帮我解决这个问题。
答
<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>
到目前为止你做了什么?你的代码在哪里失败?请阅读[如何提出一个好问题](https://stackoverflow.com/help/how-to-ask)和[如何创建一个最小化,完整且可验证的示例](https://stackoverflow.com/help/MCVE)。 – Binarus
@Binarus ..............这部分对我来说是全新的。所以我不知道如何开始,这就是为什么没有代码。 –
@Binarus ............我已经完成了正在进行的考试的计时器部分。一旦考试开始,就有一个倒数计时器,当计时器到零时,考试结束。现在我坚持这部分 –