The SetInterval method can be used to implement circular call functions at specified intervals until the Clearinterval method cancels the loop
When you cancel a loop with the Clearinterval method, you must assign the call to the SetInterval method to a variable, and then the Clearinterval method references the variable.
Copy Code code as follows:
<script type= "Text/javascript" >
var n = 0;
function print () {
Document.writeln (n);
if (n==1000) {
Window.clearinterval (s);
}
n++;
}
var s = window.setinterval (print, 10);
</script>
Completes the deferred call with SetTimeout and cleartimeout, runs the specified function after the specified delay time, and executes only once. The use of cleartimeout is the same as that of the Clearinterval method.
Copy Code code as follows:
<script type= "Text/javascript" >
function Printtime () {
var 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>