Javascript
<script language= "JavaScript" >
Implementation of pause function in/*javascript
JavaScript does not have a pause function (sleep cannot be used) while VBScript cannot use DoEvents, so writing this function implements this function.
JavaScript as a weak object language, a function can also be used as an object.
Like what:
function Test () {
Alert ("Hellow");
This. Nextstep=function () {
Alert ("NextStep");
}
}
We can call Var mytest=new Test (); Mytest.nextstep ();
We can do it when we're done. A function is divided into two parts, the same before the pause operation, put the code to be executed after the pause in this. In NeXTSTEP.
To control pause and continue, we need to write two functions to implement the pause and continue function separately.
The pause function is as follows:
*/
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
}
}
if (ind==-1) {
Ind=window.eventlist.length;
Window.eventlist[ind]=obj;
}
SetTimeout ("GoOn (" + ind + ")", 1000);
}
/*
The function places the function to be paused in the array window.eventlist, while the continuation function is called through the settimeout.
The continuation function is as follows:
*/
function GoOn (Ind) {
var obj=window.eventlist[ind];
Window.eventlist[ind]=null;
if (obj. NextStep) obj. NextStep ();
else obj ();
}
/*
The function calls the NeXTSTEP method of the function being paused, and calls the function again if there is no such method.
After the function is written, we can make the following book:
*/
function Test () {
Alert ("Hellow");
Pause (this,1000),/call suspend function
This. Nextstep=function () {
Alert ("NextStep");
}
}
</script>