settimeout (expression, interaction time)
The delay time/interaction time is in Hao seconds (1000ms=1s) settimeout at execution time, after a specified time delay after loading, execute an expression once
SetTimeout at execution time, it executes an expression at a specified time, after it has been loaded
1, Basic usage:
Execute a piece of code:
The code is as follows |
Copy Code |
var i=0; SetTimeout ("I+=1;alert (i)", 1000); |
To perform a function:
The code is as follows |
Copy Code |
var i=0; settimeout (function () {I+=1;alert (i);},1000); |
Note the difference between the two methods above.
SetTimeout () issues to be noted
The code is as follows |
Copy Code |
<script type= "Text/javascript" > function Test () { Alert ("I am global"); } function Myfun () { function Test () { Alert ("I am Partial"); } settimeout ("Test ()", 2000); To invoke global test settimeout (test, 5000); To call local test } Myfun (); </script> |
The result is the first alert out of "I am global" and then alert out "I am part of"!