javascript - 在一个文档中单独观看时间
问题描述
我找到了一个倒计时的脚本。在每个脚本中,我设置了不同的结束时间。保存文件后,每个元素中的时间都是相同的。有谁知道如何分别<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,这对我来说没有解决问题。
解决方案
推荐阅读
- c# - IServiceCollection 后配置
- powershell - Powershell - 结合 switch 语句和循环
- redis - 我可以使用 Celery 发布和订阅主题吗?
- firebase - 带有 WebView 的 Flutter 应用中的 Firebase 身份验证
- javascript - 在另一个函数中推送函数?
- javascript - 将数字转换为小时?
- java - 如何在通用文件夹中设置 JAVA_HOME
- abap - 从 ABAP 中的 mscomm 读取数据
- cas - CAS 委托身份验证:cas pac4j 中的动态客户端 ID 和机密
- python - 声波的最小表示?