Home >Web Front-end >JS Tutorial >Add parameters to settimeout method in js
This article mainly introduces the settimeout method and parameters in js. Friends who need it can refer to the use of the settimeout method and parameters in js.
Simple use, see w3school
There is no parameter call,
Example:
Copy code The code is as follows:
<script type="text/javascript"> function timedMsg() { var a ="dd"; var t=setTimeout(function(){ cao(a);},3000) } function cao(a) { alert(a); } </script> </head> <input type="button" value="显示定时的警告框" onClick = "timedMsg()">
My current problem is that between multiple ones, only the last one is returned. Think about it
Copy code Code As follows:
/* for (var i=0;i<points.length;i++){ AddGuiJi(points[i],value); //var t=setTimeout(function(){ AddGuiJi(points[i],value);},2000*i) } */
The reason for the above error is that when time is triggered for execution, i=4, so although there are multiple ones, it is always the last one
Solution
Copy code The code is as follows:
var timerr; function xunhuanlian(points,value){ if(replayiFor more articles related to adding parameters to the settimeout method in js, please pay attention to the PHP Chinese website!