SetTimeout (code,millisec)//-executes code after a specified time
Code must;
Millisec must;
Cleartimeout (Settimeoutid)//-cancel settimeout ()
SetInterval (CODE,MILLISEC),//Specify looping code within the interval milliseconds
Code must;
Millisec must;
Clearinterval (Intervalid);
Using settimeout (CODE,MILLISEC) can achieve setinterval effect, only need nested call method;
Below is a countdown page
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<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 (time>0) {
document.getElementById (' txt '). value=c;
C=c-1;
T=settimeout ("Timedcount ()", 1000);
}
else{
cleartimeout (t);
}
}
</script>
<body>
<form>
<input type= Button "value=" Start the timer! "Onclick=" Timedcount () >
<input type= "text" id= "TXT" value= "6" >
</form>
</body>