我发现了一个倒计时的脚本。在每个脚本中,我将结束时间设置为不同的时间。保存文件后,每个元素中的时间相同。有人知道如何分别解决每个 <div>
脚本中的时间吗?
<script>
// Set the date we're counting down to
var countDownDate = new Date("April 3, 2019 01:59:59").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("clockfirst").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("clockfirst").innerHTML = "EXPIRED";
}
}, 1000);
</script>
我重复了上面的代码,并将此代码三遍插入到一个文档中,并更改了每个脚本中的内容:
在脚本下方,我添加了html标签:
<div id="clockfirst"></div>
<div id="clocksecond"></div>
<div id="clockthird"></div>
@mplingjan我在此主题之前进行了检查,但并未解决问题,因此创建了新主题。是的,我为每个脚本更改了setInterval,这对我来说没有解决问题。