Js settimeout method plus the use of parameters

  • 2020-03-30 02:08:28
  • OfStack

Easy to use look at w3school

There's no argument call in there,

Examples are 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=" display timing warning box "onClick =" timedMsg()">

My problem now is between multiple, only the last one comes back. Think about it

Still not quite. Got it
 
/* 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 error in the above is that when time is triggered, I =4, so it is multiple but always the last one

The solution
 
var timerr; 
function xunhuanlian(points,value){ 
if(replayi<points.length){ 
AddGuiJi(points[replayi],value); 
replayi++; 
timerr=setTimeout(function(){ xunhuanlian(points,value);},1000); 
} 
else{ 
replayi =0; 
clearTimeout(timerr); 
} 
/* for (var i=0;i<points.length;i++){ 
AddGuiJi(points[i],value); 
//var t=setTimeout(function(){ AddGuiJi(points[i],value);},2000*i) 
} */ 
} 

Related articles: