javascript (用setTimeout而非setInterval)
更新时间:2011年12月28日 23:56:48 作者:
javascript (用setTimeout而非setInterval)如果用setInterval 可能出现 下次调用会在前一次调用前调用
复制代码 代码如下:
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中的Array.prototype.sort PK 快速排序)
今天在51js论坛中看到一个网友发布了一个javasctipt实现的快速排序的算法,前些日子工作中也涉及到javasctipt中数据排序的应用,当时为了提高排序速度,使用的也是快速排序的算法。2007-01-01
javascript css styleFloat和cssFloat
在写js操作css的过程中发现float属性在IE和firefox下对应的js脚本是不一样的,IE下对应得是 styleFloat,firefox,chorme,safari下对应的是cssFloat,可用in运算符去检测style是否包含此属性。2010-03-03


最新评论