`<script type"text/javascript"> /*Javascript中暂停功能的实现 Javascript自己没有暂停功能(sleep不能使用)同时 vbscript也不能使用doEvents,故编写此函数实现此功能。 javascript做为弱对象语言,一个函数也能够做为一个对象使用。 好比:javascript
[code] function Test(){ alert("hellow"); this.NextStep=function(){ alert("NextStep"); } } 咱们能够这样调用 var myTest=new Test();myTest.NextStep(); 咱们作暂停的时候能够吧一个函数分为两部分,暂停操做前的不变,把要在暂停后执行的代码放在this.NextStep中。 为了控制暂停和继续,咱们须要编写两个函数来分别实现暂停和继续功能。 暂停函数以下: */ function Pause(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; } }java
if (ind==-1){ ind=window.eventList.length; window.eventList[ind]=obj; } setTimeout("GoOn(" + ind + ")",1000); } /* 该函数把要暂停的函数放到数组window.eventList里,同时经过setTimeout来调用继续函数。 继续函数以下: */数组
function GoOn(ind){ var obj=window.eventList[ind]; window.eventList[ind]=null; if (obj.NextStep) obj.NextStep(); else obj(); } /* 该函数调用被暂停的函数的NextStep方法,若是没有这个方法则从新调用该函数。 函数编写完毕,咱们能够做以下册是: */ function Test(){ alert("hellow"); Pause(this,1000);//调用暂停函数 this.NextStep=function(){ alert("NextStep"); } } </script>`函数