x
 
<!DOCTYPE html>
<html>
<body onload="startTime()">
<h1>Window 对象</h1>
<h2>setTimeout 方法</h2>
<p id="demo"></p>
<script>
function startTime() {
  const date = new Date();
  document.getElementById("demo").innerHTML = date.toLocaleTimeString();
  setTimeout(function() {startTime()}, 1000);
}
</script>
</body>
</html>