gpt4 book ai didi

javascript - insideHTML 在 setInterval 上不改变

转载 作者:行者123 更新时间:2023-11-28 20:25:09 24 4
gpt4 key购买 nike

在此 JavaScript 中,“剩余秒数”应该每秒减少,但这种情况不会发生。
innerhtml不要更改 <span id='timer'> 的值而innerHTML对于 <span id='id'>正在工作。

<script>
var lastdate=1373814606250;
var today=1373388292527;
var d,h,m,s;
function displayDate()
{
today--;
d=(lastdate-today)/86400000;
h=(d-Math.floor(d))*24;
m=(h-Math.floor(h))*60;
s=(m-Math.floor(m))*60;
document.getElementById("timer").innerHTML=Math.floor(d)+" Days "+Math.floor(h)+" hours "+Math.floor(m)+" minutes "+Math.floor(s)+" seconds";
document.getElementById('id').innerHTML=today;
}
</script>
<body onload="setInterval('displayDate()',1000)">
<span id='timer'></span><br/>
<span id='id'></span>
</body>

查看Working here

编辑
这里的今天和最后日期是以毫秒为单位的日期。

最佳答案

我明白计算秒时存在逻辑错误。
应该是

today=today+1000;

因为毫秒而不是秒

关于javascript - insideHTML 在 setInterval 上不改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17554150/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com