This article mainly introduced the JavaScript interval call and the delay call example, introduced the SetInterval method and the Clearinterval method use method, everybody reference uses the bar
The SetInterval method enables circular call functions to be implemented at specified intervals until the Clearinterval method cancels the loop cancels the loop with the Clearinterval method, the call to the SetInterval method must be assigned to a variable, The Clearinterval method then references the variable. Code as follows: <script type= "Text/javascript" > var n = 0; function print () { Document.writeln (n); if (n== 1000) { Window.clearinterval (s); } &NBS P n++; } var s = window.setinterval (print, 10); </script> Use settimeout and cleartimeout to complete the deferred call, run the specified function after the specified delay time, and execute only once. The use of cleartimeout is the same as that of the Clearinterval method. Code as follows: <script type= "Text/javascript" > function printtime () { V Ar time = new Date (); var year = Time.getfullyear (); var month = (Time.getmonth ()) +1; var daynum = Time.getday ();   var hour = time.gethours (); var min = time.getminutes (); var sec = Time.getseconds (); var da = time.getdate (); var daystr; switch (daynum) { case 0:daystr= "Sunday"; break; case 1:daystr= "Monday"; break; case 2:daystr= "Tuesday"; break; case 3:daystr= "Wednesday"; break; case 4:daystr= "Thursday"; break; case 5:daystr= "Friday"; break; case 6:daystr= "Saturday"; break;   default:daystr= ""; } var str = year+ "year" +month+ "month" +da+ "Day " +daystr+ "" +hour+ ":" + min+ ":" +SEC; document.getElementById ("T"). InnerHTML = str; Window.settimeout (printtime, 1000); } </script> <body onload= "Printtime ()" > <br/> <div id= "T" ></div> < /body>