手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >javascript (用setTimeout而非setInterval)
javascript (用setTimeout而非setInterval)
摘要:复制代码代码如下:varnum=0;varmax=10;functionincrementNumber(){num++;//ifthemax...

复制代码 代码如下:

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)

【javascript (用setTimeout而非setInterval)】相关文章:

详谈javascript中的cookie

JavaScript 正则表达式中global模式的特性

Javascript中With语句用法实例

理解javascript定时器中的setTimeout与setInterval

JavaScript AOP编程实例

javascript中clipboardData对象用法

javascript实现仿腾讯游戏选择

JavaScript 定时器 SetTimeout之定时刷新窗口和关闭窗口(代码超简单)

JavaScript中eval函数的问题

JavaScript基于setTimeout实现计数的方法

精品推荐
分类导航