javascript 的計時器,類似vb.net的timer():
請等5秒,才顯示歡迎詞
範例1:t1 = setTimeout("alert('生日快樂')", 5000);
範例2:t1 = setTimeout(function(){alert('生日快樂')}, 5000);
範例3:t1 = setTimeout(show2, 5000);
注意:函數show2不可以加上()
(2).關閉計時器語法:clearTimeout(計時器變數),只會執行1次;
範例1:clearTimeout(t1)
- setTimeout(function, milliseconds)
Executes a function, after waiting a specified number of milliseconds.
- setInterval(function, milliseconds)
Same as setTimeout(), but repeats the execution of the function continuously.