innerHTML在setInterval上没有改变

时间:2013-07-09 17:06:54

标签: javascript html date setinterval innerhtml

在这个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> 1}}正在运作。

{{1}}

Working here

修改
今天和lastdate是以毫秒为单位的日期。

2 个答案:

答案 0 :(得分:2)

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

today=today+1000;

因为毫秒而不是秒

答案 1 :(得分:1)

第一个跨度的innerHTML也有效 但内容永远不会改变。 Math.floor(d)+" Days "+Math.floor(h)+" hours "+Math.floor(m)+" minutes "+Math.floor(s)+" seconds"每次都会给出相同的结果。

相关问题