[SetTimeout]
SetTimeout (expression, latency)
During execution, an expression is executed after a specified time delay after loading,The number of times is once
[Setinterval]
Setinterval (expression, interaction time)
It is different. After it is loaded,Execute at specified timeOne expression
Because this is often used and I have to remember it completely every time, I always need to search the Internet once. It is too troublesome to write a test page by myself.
<HTML>
<Head>
<Title> setTimeout and setinterval test cases </title>
</Head>
<Body>
<Script language = "JavaScript">
// Set global variables
VaR staticobj = {};
Staticobj. Timer = "";
Staticobj. timer2 = "";
Staticobj. Count = 0;
Function startreload ()
{
// Set interval
Staticobj. Timer = setinterval ("reloaddata ()", 500 );
}
Function stopreload ()
{
// Clear Interval
Clearinterval (staticobj. Timer );
}
Function reloaddata ()
{
Staticobj. Count ++;
Alert ("interval cycles:" + staticobj. Count );
If (staticobj. Count = 5)
{
Stopreload ();
Alert ("the interval loop has ended! Start to enter the setTimeout function ");
// Set timeout
Staticobj. timer2 = setTimeout (timeoutfn, 100 );
}
}
Function timeoutfn ()
{
Cleartimeout (staticobj. timer2 );
Alert ("the setTimeout function is executed and the object is cleared ");
}
Startreload ();
</SCRIPT>
</Body>
</Html>