This article mainly introduces the difference between interval and settimeout in JavaScript, and need friends can refer to the following
SetTimeout (code,millisec)//-execute code after a specified time code must; MILLISEC must; cleartimeout ( Settimeoutid)//-Cancel settimeout () setinterval (CODE,MILLISEC);//Specify Loop execution code in interval milliseconds code must be; & nbsp Millisec must be; clearinterval (intervalid); with settimeout (CODE,MILLISEC) to achieve setinterval effect, Only nested call methods are required; below is a countdown page code as follows: <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html xmlns=" http://www.w3.org/1999/xhtml "> <head> <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/> <title> Untitled document </title> <script type=" Text/javascript "> var c =6; var t; function timedcount () { var time = document.getElementById (' txt ') .value; if (Tim e>0) { document.getElementById (' txt ') .value=c; c=c-1; t=settimeout ("TimedCount ()", 1; } else{ cleartimeout (t); } } </script> </head> <body> <form> <input type= "button" value= "Start the timer! "Onclick=" Timedcount () "> <input type=" text "id=" TXT "value=" 6 "> </form> </body > </html>