倒数计时器使用php激活按钮点击

时间:2017-09-26 06:13:30

标签: javascript php mysql ajax

需要一个帮助guyz,我的方案是 - 在我的数据库中,我有一个带有列的表" created_time"它将当前系统时间存储在HH:MM AM / PM中。现在我希望只要在当前系统时间输入该表中的数据,然后在我的一个php页面中就会出现一个名为" Start Exam"的按钮,当前该按钮将被禁用" #34;状态,应该在数据库输入1小时后准确启用,同时显示倒计时器和按钮。

任何人都可以帮助我。

1 个答案:

答案 0 :(得分:0)

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