Use the SetInterval method to use the specified interval to implement the circulating function until the Clearinterval method cancels the cycle
When using the Clearinterval method to cancel the loop, the call of the SetInterval method must be assigned to a variable, and then the ClearInterval method references the variable.
Copy code code as follows:
<script type = "text/javascript">
var n = 0;
function prop () {) {
document.writeln (n);
if (n == 1000) {
Window.Clearinterval (s);
}
n ++;
}
var s = window.Setinterval (Print, 10);
</script>
Use Settimeout and Cleartimeout to complete the delayed call, run the specified function after the specified delay time, and only execute it once. Cleartimeout's usage is the same as the Clearinterval method.
Copy code code as follows:
<script type = "text/javascript">
function proptime () {
var time = new date ();
var years = time.getfullyear ();
varmth = (time.getmonth ())+1;
var daynum = time.getdy ();
var hours = time.gethouse ();
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 only = "printtime ()">
<br/>
<div ID = "T"> </DIV>
</body>