Window objects have two main timing Methods: setTimeout and setinteval. Their syntaxes are basically the same, but their functions are different.
The setTimeout method is timed.ProgramThat is, after what time. After the job is finished, pull it down.
The setinterval method indicates that an operation is executed repeatedly at a certain interval.
If you use setTimeout to implement the setinerval function, you need to regularly call yourself in the executed program. To clear a counter, you need to call different clearing methods based on the method used:
Example: tttt = setTimeout ('northsnow () ', 1000 );
Cleartimeout (tttt );
Or:
Tttt = setinterval ('northsnow () ', 1000 );
Clearinteval (tttt );
For example:
<Div id = "liujincai"> </div>
<Input type = "button" name = "start" value = "start" onclick = 'startshow (); '>
<Input type = "button" name = "stop" value = "stop" onclick = "Stop ();">
<Script language = "JavaScript">
VaR intvalue = 1;
VaR timer2 = NULL;
Function startshow ()
{
Liujincai. innerhtml = liujincai. innerhtml + "& nbsp;" + (intvalue ++). tostring ();
Timer2 = Window. setTimeout ("startshow ()", 2000 );
}
Function stop ()
{
Window. cleartimeout (timer2 );
}
</SCRIPT>
Or: