我正在尝试制作时间和日期时钟。尝试调用函数时遇到各种错误:
<html>
<head>
<title>Very Simple Clock By Ashton</title>
<script>
console.log("beginning creation of update function");
function update() {
document.getElementById('timeOutput').innerHTML = Date();
}
console.log("Successfully created update function");
console.log("Calling the update function")
update();
console.log("successfully called the update function");
</script>
</head>
<body>
<p onload="update()" id="timeOutput">ERROR | Could Not Retrieve Time from server</p>
</body>
答案 0 :(得分:0)
Body,Img,Iframe广告代码仅支持onload
事件p
。因此,请使用onclick
事件更改,而不是onload
仅加载p
console.log("beginning creation of update function");
function update() {
document.getElementById('timeOutput').innerHTML = Date();
}
<p onload="update()" id="timeOutput">ERROR | Could Not Retrieve Time from server</p>
更改以单击
console.log("beginning creation of update function");
function update() {
document.getElementById('timeOutput').innerHTML = Date();
}
console.log("Successfully created update function");
console.log("Calling the update function")
update();
console.log("successfully called the update function");
<p onclick="update()" id="timeOutput">ERROR | Could Not Retrieve Time from server</p>
答案 1 :(得分:0)
Onload不适用于EventEmitter
标签,因此没有用。
将<p>
放在update()
内将使其起作用。