javascript 的計時器,類似vb.net的timer():
請等5秒,才顯示歡迎詞
(1).語法:setInterval(時間到了要執行的函數(),毫秒1000代表1秒),會重複一直執行
範例1:t1 = setInterval("alert('生日快樂')", 5000);
範例2:t1 = setInterval(function(){alert('生日快樂')}, 5000);
範例3:t1 = setInterval(show2, 5000);
注意:函數show2不可以加上()
(2).關閉計時器語法:clearInterval(計時器變數),只會執行1次;
範例1:clearInterval(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.