我讀了關於計時事件。我很困惑setTimeout
:我在W3School上有一個例子,它每500毫秒運行一次。我讀了約setTimeout
,它只有一次。 link爲什麼setTimeout函數永遠執行?
<head>
<script>
function startTime() {
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
setTimeout(function(){startTime()},500);
}
</script>
</head>
<body onload="startTime()">
<div id="txt"></div>
</body>
[請小心使用w3schools作爲參考。](http://w3fools.com) – Pointy