正在尝试在小型计算器中显示时间(小时,分钟,秒),但正在接收异常错误消息==> {2VM6:1 Uncaught ReferenceError:未定义计时器在:1:1}。认为setInterval方法导致了该错误,我的脚本低于我所认为的d错误来自于他们。
```<!DOCTYPE html>
<html lang="en">
<head>
<script src="script.js"></script>
<link rel="stylesheet" href="style.css"/>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="container">
<div id="time">chinaza</div>
<div class="item_1" id="display_container"></div>
<div class="item_1" id="result"></div>
<div class="item_1" id="key_container">
<table>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
<td>del</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
<td>/</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>-</td>
</tr>
<tr>
<td>.</td>
<td>0</td>
<td>=</td>
<td>+</td>
</tr>
</table>
</div>
</div>
</body>
</html>
window.onload=function(){
function timer(){
let time =new Date();
let hour=time.getHours();
let min=time.getMinutes();
let sec=time.getSeconds();
console.log(hour,min,sec);
document.getElementById("time").innerHTML=sec;
}
setInterval("timer()",1000);
}```
试图在小型计算器中显示时间(小时,分钟,秒),但正在接收异常错误消息==> {2VM6:1 Uncaught ReferenceError:计时器未定义为:1:1}。认为setInterval ...
您不想在引号中传递这样的计时器。这是您应该可以使用的工作笔: