Home >Web Front-end >JS Tutorial >Add parameters to settimeout method in js

Add parameters to settimeout method in js

高洛峰
高洛峰Original
2017-02-08 16:11:451153browse

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(replayi

For more articles related to adding parameters to the settimeout method in js, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn