setTimeout()--is used to specify that a program is executed after a specific period of time.
Format:
[Timer object name=]setTimeout("<expression>", milliseconds);
Function: Execute <expression> once.
Where the expression is a string, you can make any javascript statement
The code copy is as follows:
<html>
<head>
<script type="text/javascript">
//Execute alert after 5 seconds
function count(){
setTimeout("alert('Execution Successful');",5000);
}
</script>
</head>
<body>
<input type="button" value="execute" onclick="count()">
</body>
</html>
setInterval() - Repeat the execution of <expression> until the window or frame is closed or clearInterval is executed
Format: [Timer object name=]setInterval("<expression>", milliseconds)
clearInterval() terminates the timer
Format: clearInterval (timer object name)
The code copy is as follows:
<html>
<head>
<script type="text/javascript">
var sec=0;
var timeId=setInterval("count();",1000);
function count(){
document.getElementById("num").innerHTML=sec++;
}
function stopCount(){
clearInterval(timeId);
}
</script>
</head>
<body>
<font style="color:red" id="num">0</font>seconds<input type="button" value="stop" onclick="stopCount();">
</body>
</html>
Is it very useful? Please refer to it if you need it.