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 a Timer Program, that 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:
<Div id = "liujincai"> </div>
<Input type = "button" name = "start" value = "start" onclick = 'timer2 = window. setInterval ("startShow ()", 2000); // 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 ();
}
Function stop ()
{
Window. clearInterval (timer2 );
}
</Script>