DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> javascript (用setTimeout而非setInterval)
javascript (用setTimeout而非setInterval)
編輯:關於JavaScript     
復制代碼 代碼如下:
var num = 0;
var max = 10;
function incrementNumber() {
num++;
//if the max has not been reached, set another timeout
if (num < max) {
setTimeout(incrementNumber, 500);
} else {
alert(“Done”);
}
}
setTimeout(incrementNumber, 500);

如果用setInterval 可能出現 下次調用會在前一次調用前調用 (

True intervals are rarely used in production environments because it ' s possible that one interval will begin before the previous one has finished executing)
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved