【发布时间】:2019-03-19 00:07:52
【问题描述】:
我对 Javascript 非常陌生,并且不太了解它。但是,我已经设法创建了一个倒数计时器,它可以像我想要的那样半工作。它非常简单,但它基本上是一个倒计时到特定日期的计时器,然后一旦达到指定的日期和时间,它就会显示我可以自定义的文本。 一旦倒计时达到零,我希望这段代码能够显示带有超链接的按钮。这是我到目前为止的代码:
// Set the date we're counting down to
var countDownDate = new Date(Date.now() + 20000).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 and 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 + " days, " + hours + " hours, " +
minutes + " minutes, & " + seconds + " seconds";
// If the count down is over, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "We're Live on Facebook!";
}
}, 1000);
<p id="demo" class="countdown-live" style="text-align:center;"></p>
任何帮助让它显示一个超链接按钮而不是文本“我们在 Facebook 上直播!”将不胜感激。
【问题讨论】:
-
所以更改显示文本的行。
document.getElementById("demo").innerHTML = "We're Live on Facebook!";我没有看到你试图解决这个问题。
标签: javascript html countdown