更新 JavaScript
我正在尝试用 Javascript 创建一个更新时钟。当我单步执行调试器时,一切都正常工作,只是它实际上并未更新跨度。有什么想法吗?
<script type="text/javascript">
// The following line of code is in a setInterval()
// time is set correctly, according to my debugger
document.getElementById('clock').value = time;
}
</script>
<span id="clock">This should update
</span>
I'm trying to create an updating clock in Javascript. Everything is working correctly as I step through the debugger, except that it's not actually updating the span. Any ideas why?
<script type="text/javascript">
// The following line of code is in a setInterval()
// time is set correctly, according to my debugger
document.getElementById('clock').value = time;
}
</script>
<span id="clock">This should update
</span>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
value
更改为innerHTML
value
仅是input
或option
等表单元素的有效属性代码>.Change
value
toinnerHTML
value
is only a valid attribute for form elements likeinput
oroption
.另外,要刷新它(如果您正在做时钟),请使用 window.setTimeout;
500 是毫秒值。
Also, to have it refresh (if you are doing a clock), use window.setTimeout;
500 is millisecond value.