[英]onload event is not working in body tag using JavaScript
I want to show the date and time after onload
event of the body
tag but it is not working, the JavaScript method is not calling. 我想在
body
标签的onload
事件之后显示日期和时间,但是它不起作用,JavaScript方法未调用。
Here is my code 这是我的代码
<script>
function display_c() {
var refresh = 1000; // Refresh rate in milli seconds
mytime = setTimeout('display_ct()', refresh)
}
function display_ct() {
alert();
var strcount
var x = new Date()
document.getElementById('ct').innerHTML = x;
tt = display_c();
}
</script>
<body onload="display_ct()">
<div style="width:300px; float:left;">
<span id='ct'></span>
</div>
</body>
The onload
event should work, but display_ct()
is not calling and the alert never appears. onload
事件应该可以工作,但是display_ct()
没有调用,并且永远不会出现警报。
Seems to be working correctly 似乎正常工作
function display_c() { var refresh = 1000; // Refresh rate in milli seconds mytime = setTimeout('display_ct()', refresh); } function display_ct() { var strcount; var x = new Date(); document.getElementById('ct').innerHTML = x; alert(x); tt = display_c(); }
<body onload="display_ct()"> <div style="width:300px; float:left;"> <span id='ct'></span> </div> </body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.