The SetTimeout method is the timer program, which is what to do after the time. Just finish it.
The SetInterval method is to indicate that an operation is repeated at a certain time interval.
If you implement the function of Setinerval with settimeout, you need to call yourself in the program you are executing. If you want to clear the counter you need to invoke different cleanup methods depending on the method you are using:
For example:
Tttt=settimeout (' Northsnow () ', 1000);
Cleartimeout (TTTT);
Or:
Tttt=setinterval (' Northsnow () ', 1000);
Clearinteval (TTTT);
Give an example:
Copy Code code as follows:
<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 + "" + (Intvalue + +). toString ();
Timer2=window.settimeout ("Startshow ()", 2000);
}
function Stop ()
{
Window.cleartimeout (TIMER2);
}
</script>
Or:
Copy Code code as follows:
<div id= "Liujincai" ></div>
<input type= "button" Name= " Start "value=" Start "onclick= ' Timer2=window.setinterval (" Startshow () ");//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 + " " + (Intvalue + +). toString ();
}
Function Stop ()
{
Window.clearinterval (timer2);
}
</script>