JavaScript setInterval() method either call a function evaluates an expression at specified number of milliseconds. This method continues to call/evaluate the expression until window is called. Another way to stop this method is by calling clearInterval() method. Below is a working demo of this useful method.
Hit start..
This method is very handy on requirement of executing an action over over again. The below example script illustrates the setInterval() method. It takes a function with one second delay, in this case its 1000 millisecond.
123456789101112131415var
dateId4AutoGen;
function
autoGenerateDt() {
var
dateAuto =
new
Date();
document.getElementById(
"datePnlAuto"
).innerHTML = dateAuto;
}
function
autoDtSrt() {
if
(dateId4AutoGen) {
clearInterval(dateId4AutoGen);
}
dateId4AutoGen = setInterval(
function
() {
autoGenerateDt();
},
1000
);
};
No comments:
Post a Comment