这是我的代码在我目前的程序。我有一个倒计时计时器的运行代码,现在我的问题是投票时间结束时我想显示投票结束,而不是总是显示投票打开。设置倒数计时器,然后显示投票打开,然后投票时间显示投票结束
<script>
// Set the date we're counting down to
var countDownDate = new Date("<?php echo $countdown['datestart']; ?>").getTime();
var endDate = new date("<?php echo $countdown['dateend']; ?>").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);
// Output the result in an element with id="demo"
document.getElementById("demo").innerHTML = days + "d " + hours + "h "
+ minutes + "m " + seconds + "s ";
// If the count down is over, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "Voting now Opens";
}
// If date end is over display some text
//display voting period ends
}, 1000);
</script>
没有必要展示PHP,只是给它分析什么,也有一个错字在这里。代码不会运行(例如:'new date'应该是'new Date')。 –
你到目前为止已经尝试过什么来显示投票结束?也许在投票结束后添加一个'setTimeout()'或检查当前时间到结束时间?如果时间/日期超过关闭时间/日期... – NewToJS
如何做一个setTimeout()?我做的是投票打开。我想在var endDate大于NOW时显示投票结束 –