Timer 1
Used to specify a program to be executed after a certain period of time.
SetTimeout ():
Format: [Timer object name =] SetTimeout ("< expression >", ms)
Function: Execute < expression > once.
Example:
Copy Code code as follows:
<! DOCTYPE html>
<title>timer1.html</title>
<meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3" >
<meta http-equiv= "description" content= "This are my page" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<!--<link rel= "stylesheet" type= "Text/css" href= "./styles.css" >-->
<script type= "Text/javascript" >
function count ()
{
SetTimeout (' Alert (' execution succeeded! ') ", 7000);
}
</script>
<body>
<input type= "button" value= "click Me" onclick= "count ();" >
</body>
Timer 2
Repeats an expression repeatedly, at a certain time interval.
SetInterval ():
Format: [Timer object name =] SetInterval ("< expression >", ms)
Function: Repeat execution < expression until the window, frame is closed, or the clearinterval is executed.
Clearinterval ():
Format: clearinterval (Timer object name)
Function: Termination timer
Example:
Copy Code code as follows:
<! DOCTYPE html>
<title>timer2.html</title>
<meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3" >
<meta http-equiv= "description" content= "This are my page" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<!--<link rel= "stylesheet" type= "Text/css" href= "./styles.css" >-->
<script type= "Text/javascript" >
var sec = 0;
The var timer = setinterval ("count ();", 1000);//When the page loads, the timer starts
function count ()
{
document.getElementById ("num"). InnerHTML = sec++;
}
function Stopcount ()
{
Clearinterval (timer);/Stop timer running
}
</script>
<body>
<font color= "Red" id= "num" >0</font>
<input type= "button" value= "Stop" onclick= "Stopcount ();" >
</body>
The above is the entire content of this article, I hope you can enjoy