Document methods:
Cyclic execution: var timeid = window. setInterval ("method name or method", "latency"); window. clearInterval (timeid );
Scheduled execution: var tmid = window. setTimeout ("method name or method", "latency"); window. clearTimeout (tmid );
Example:
A. When parameters are not required in the method to be executed
Copy codeThe Code is as follows:
<Script type = "text/javascript">
// Execute cyclically, and execute showalert () every three seconds ()
Window. setInterval (showalert, 3000 );
Function showalert ()
{
Alert ("aaaaa ");
}
// Scheduled execution. Execute show () in 5 seconds ()
Window. setTimeout (show, 5000 );
Function show ()
{
Alert ("bbb ");
}
</Script>
B. When parameters are required in the method to be executed
Copy codeThe Code is as follows:
<Script type = "text/javascript">
// Execute cyclically, and execute showalert () every three seconds ()
Window. setInterval (function (){
Showalert ("aaaaa ");
},3000 );
Function showalert (mess)
{
Alert (mess );
}
// Run the showalert () command in five seconds ()
Window. setTimeout (function (){
Showalert ("bbbbbb ");
},5000 );
</Script>