Both setTimeout and setintelval have the timer function !!! When the scheduled task is canceled, cleartimeout and clearinterval correspond to each other.
But there is a difference between them!
SetTimeout indicates that the task is executed only once after a period of time.
Setinterval indicates that the execution is performed multiple times at intervals.
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en"> <br/> <HTML> <br/> <pead> <br/> <title> new document </title> <br/> <meta name = "generator" content = "editplus"> <br/> <meta name = "author" content = ""> <br/> <meta name = "keywords" content = ""> <br/> <meta name = "Description" content = ""> <br/> </pead> </P> <p> <body> <br/> <Div id = "time"> </div> <br/> <script language = "JavaScript"> <br/> <! -- <Br/> var timeid; <br/> function settime () {<br/> var date = new date (); <br/> var H = date. gethours (); <br/> var M = date. getminutes (); <br/> var S = date. getseconds (); <br/> document. getelementbyid ("time "). innerhtml = H + ":" + M + ":" + S; <br/>}< br/> timeid = setinterval ("settime ()", 1000 ); // Its call is an external call, instead of a recursive call. It indicates that the call is performed once every 1 S. <br/> function stop () {<br/> clearinterval (timeid ); <br/>}< br/> // --> <br/> </SCRIPT> <br/> <input type = "button" value = "Suspend" onclick =" stop () "> <br/> <input type =" button "value =" start "onclick =" timeid = setinterval ('settime () ', 1000 ); "> <br/> </body> <br/> </ptml> </P> <p>
SetTimeout
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en"> <br/> <HTML> <br/> <pead> <br/> <title> new document </title> <br/> <meta name = "generator" content = "editplus"> <br/> <meta name = "author" content = ""> <br/> <meta name = "keywords" content = ""> <br/> <meta name = "Description" content = ""> <br/> </pead> </P> <p> <body> <br/> <Div id = "time"> </div> <br/> <script language = "JavaScript"> <br/> <! -- <Br/> var timeid; <br/> function settime () {<br/> var date = new date (); <br/> var H = date. gethours (); <br/> var M = date. getminutes (); <br/> var S = date. getseconds (); <br/> document. getelementbyid ("time "). innerhtml = H + ":" + M + ":" + S; <br/> timeid = setTimeout ("settime ()", 1000); // recursive call, 1 s later <br/>}< br/> settime (); // start execution after page loading <br/> function stop () {<br/> cleartimeout (timeid ); <br/>}< br/> // --> <br/> </SCRIPT> <br/> <input type = "button" value = "Suspend" onclick =" stop () "> <br/> <input type =" button "value =" start "onclick =" timeid = setinterval ('settime () ', 1000 ); "> <br/> </body> <br/> </ptml> <br/>