xml地图|网站地图|网站标签 [设为首页] [加入收藏]

软件资讯

当前位置:美高梅游戏网站 > 软件资讯 > javascript (用setTimeout而非setInterval)

javascript (用setTimeout而非setInterval)

来源:http://www.gd-chuangmei.com 作者:美高梅游戏网站 时间:2019-09-05 18:23

复制代码 代码如下:

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)

代码如下: var num = 0; var max = 10; function incrementNumber() { num++; //if the max has not been reached, set another timeout if (num max) { setTimeout(increment...

本文由美高梅游戏网站发布于软件资讯,转载请注明出处:javascript (用setTimeout而非setInterval)

关键词: