Web page effects settimeout and SetInterval Execute command function method periodically
settimeout (expression, delay time)
At execution time, after the specified time is delayed, the expression is executed once, remembering that the number is once
Automatic changes with settimeout to display the effect of random numbers:
Window.settimeout ("Softphoneui.unregistergk ()", 10000000);
Or
Window.settimeout (softphoneui.unregistergk,10000000);
settimeout (expression, interaction time)
The delay time/interaction time is in Hao seconds (1000ms=1s) settimeout at execution time, after a specified time delay after loading, execute an expression once
SetTimeout at execution time, it executes an expression at a specified time, after it has been loaded
1, Basic usage:
Execute a piece of code:
Copy code code as follows:
var i=0;
SetTimeout ("I+=1;alert (i)", 1000);
To perform a function:
Copy code code as follows:
var i=0;
settimeout (function () {I+=1;alert (i);},1000);
Note the difference between the two methods above.
Here's another executive function:
Copy code code as follows:
var i=0;
function Test () {
I+=1;
alert (i);
}
settimeout ("Test ()", 1000);
You can also do this:
Copy code code as follows:
SetTimeout (test,1000);
Summarize:
The prototype of settimeout is this:
Itimerid = Window.settimeout (Vcode, Imilliseconds [, slanguage])
There are two forms of settimeout
SetTimeout (Code,interval)
SetTimeout (Func,interval,args)
Where code is a string
Func is a function.
Note that the meaning of "function" is an expression, not a statement.
Like you want to perform a function periodically
function A () {
//...
}
can be written as
SetTimeout ("A ()", 1000)
Or
SetTimeout (a,1000)
How to use SetInterval
[SetInterval]
SetInterval (expression, interaction time)
is not the same, it executes an expression once at a specified time from loading
Automatic changes with setinterval to display the effect of random numbers:
<script>
Function sett ()
{
Document.body.innerhtml=math.random ();
}
SetInterval ("Sett ();",
</script>
</script>
<body>
</body>