SetTimeout ()--Used to specify a program to be executed after a certain period of time.
Format:
[Timer object name =]settimeout ("< expression >", number of milliseconds);
Function: Execute < expression > once.
Where an expression is a string, you can make any JavaScript statement
Copy Code code as follows:
<script type= "Text/javascript" >
Execute alert after 5 seconds.
function count () {
SetTimeout ("Alert (' execution success ');", 5000);
}
</script>
<body>
<input type= "button" value= "Execute" onclick= "count ()" >
</body>
SetInterval ()-Repeat execution < expression until the window, frame is closed, or executed clearinterval
Format: [Timer object name =]setinterval ("< expression >", ms)
Clearinterval () Termination timer
Format: clearinterval (Timer object name)
Copy Code code as follows:
<script type= "Text/javascript" >
var sec=0;
var timeid=setinterval ("Count ();", 1000);
function count () {
document.getElementById ("num"). innerhtml=sec++;
}
function Stopcount () {
Clearinterval (Timeid);
}
</script>
<body>
<font style= "color:red" id= "num" >0</font> sec <input type= "button" value= "Stop" onclick= "Stopcount ();" >
</body>
is not very easy to use, there is a need for small partners under the reference bar.