脚 本 之 家 www.jb51.net
页面导航: 首页网络编程JavaScriptjavascript技巧 → 正文内容

JavaScript实现Sleep函数的代码

发布:dxy 字体:[增加 减小] 类型:转载
复制代码 代码如下:

function Sleep(obj,iMinSecond)
{
if (window.eventList==null)
window.eventList=new Array();
var ind=-1;
for (var i=0;i<window.eventList.length;i++)
{
if (window.eventList[i]==null)
{
window.eventList[i]=obj;
ind=i;
break;
}
}
if (ind==-1)
{
ind=window.eventList.length;
window.eventList[ind]=obj;
}
setTimeout("GoOn(" + ind + ")",iMinSecond);
}
function GoOn(ind)
{
var obj=window.eventList[ind];
window.eventList[ind]=null;
if (obj.NextStep) obj.NextStep();
else obj();
}
function Test()
{
alert("sleep");
Sleep(this,100);
this.NextStep=function()
{
alert("continue");
}
}

文章评论

共有 位脚本之家网友发表了评论我来说两句

最 近 更 新
热 点 排 行