Javascript examples for Browser Object Model:Window setInterval
The setInterval() method calls a function or evaluates an expression at intervals in milliseconds.
window.setInterval(function,milliseconds, param1, param2,...);
Parameter | Description |
---|---|
function | Required. The function that will be executed |
milliseconds | Required. The intervals to execute the code. |
param1, param2, ... | Optional. Additional parameters to pass to the function |
A Number, representing the ID value of the timer that is set.
The following code shows how to create a clock.
<!DOCTYPE html> <html> <body> <p id="demo"></p> <script> var myVar = setInterval(function(){ myTimer() }, 1000); function myTimer() {//from w ww . j a v a 2s .c o m var d = new Date(); var t = d.toLocaleTimeString(); document.getElementById("demo").innerHTML = t; } </script> </body> </html>