开发者

Updating Javascript

开发者 https://www.devze.com 2022-12-15 18:07 出处:网络
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 ac开发者_运维知识库tually updating the span. Any ideas why?

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 ac开发者_运维知识库tually 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>


Change value to innerHTML

document.getElementById('clock').innerHTML = time;

value is only a valid attribute for form elements like input or option.


Also, to have it refresh (if you are doing a clock), use window.setTimeout;

window.setTimeout(function() { document.getElementById('clock').innerHTML = 'XYZ'; }, 500);

500 is millisecond value.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号