I'm trying to make my timer automatically change to a second new Date()
after the first countdown is expired .(我试图使我的计时器在第一次倒数计时到期后自动更改为第二个new Date()
。)
The purpose of this is in case I need to change date for the countdown, I won't have to manually edit and upload the js file after the it has expired.(这样做的目的是在需要更改倒计时日期的情况下,它不再需要手动编辑和上传js文件。) However I haven't managed to figure out how yet.(但是我还没有弄清楚怎么做。)
Below is the script that I've tried, output is "EXPIRED".(下面是我尝试过的脚本,输出为“ EXPIRED”。) Where did I do wrong?(我在哪里做错了?) Thanks for your support!(感谢您的支持!)
<script>
// Set the date we're counting down to
var countDownDate = new Date("Jan 5, 2020 14:00:00").getTime();
var countDownDate2 = new Date("Jan 15, 2020 14:00:00").getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = countDownDate - now;
var distance2 = countDownDate2 - now;
var a = distance;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(a / (1000 * 60 * 60 * 24));
var hours = Math.floor((a % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((a % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((a % (1000 * 60)) / 1000);
// Output the result in an element with id="demo"
document.getElementById("demo").innerHTML = days + "d " + hours + "h "
+ minutes + "m " + seconds + "s ";
// Change to another exp.
if (distance < 0 && distance2 >0) {
function changeDate() {
a = distance2;
}
}
// If the count down is over, write some text
else {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
</script>
ask by Jacob D. translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…