The
1,html Dom SetInterval () method
Definition and Usage
SetInterval () method can call a function or a calculation expression in the specified period (in milliseconds). The
SetInterval () method calls the function continuously until the clearinterval () is called or the window is closed. The ID value returned by setinterval () can be used as an argument to the Clearinterval () method.
Syntax
setinterval (code,millisec[, "Lang"])
Parameter description
code required. The function to invoke or the code string to execute.
Millisec must be. The time interval, in milliseconds, between the periodic execution or invocation of code.
return value
A value that can be passed to Window.clearinterval () to cancel the periodic execution of code. The
2,html Dom Clearinterval () method
Definition and Usage
Clearinterval () method cancels the timeout set by SetInterval (). The parameter of the
Clearinterval () method must be the ID value returned by setinterval (). The
Syntax
Clearinterval (id_of_setinterval)
Parameter Description
Id_of_setinterval the ID value returned by setinterval ().
How to stop:
The following example calls the clock () function every 50 milliseconds. You can also use a button to stop this clock:
<body>
<input type= "text" id= "clock" size= ""/>
<script language= Web page Special effects >
var int=self.setinterval ("Clock ()", 50)
function Clock ()
{
var t=new date ()
document.getElementById ("Clock"). value=t
}
</script>
</form>
<button onclick= "int=window.clearinterval (int)" >
Stop interval</button>
</body>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
To learn more about settimeout:
1,html Dom SetTimeout () method
Definitions and usage
The settimeout () method is used to call a function or evaluate an expression after a specified number of milliseconds.
Grammar
SetTimeout (CODE,MILLISEC)
Parameter description
Code required. The JavaScript code string to execute after the function to be invoked.
Millisec required. The number of milliseconds to wait before executing the code.
Tips and comments
Tip: settimeout () executes only one code at a time. If you want to call more than once, use SetInterval () or let code itself call SetTimeout () again.
Example, this example, after you click the button for 5 seconds will pop up a prompt box:
<script type= "Text/javascript" >
function timedmsg ()
{
var t=settimeout ("Alert (' 5 seconds! ')", 5000)
}
</script>
<body>
<form>
<input type= "button" value= "Display timed alertbox!"
Onclick= "timedmsg ()" >
</form>
<p>click on the button above. An alert box would be
Displayed after 5 seconds.</p>
</body>