在javascript中为循环设置间隔时间 [英] set intervel time in javascript for loop

查看:119
本文介绍了在javascript中为循环设置间隔时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//THis is a java script code part please i am passing function with the for loop but i want pass j values take 2sec time interval

      for(var j=1; j<=n;j++)
        {

                setInterval(function(){calcRoute(ss,j); alert("time");},2000);
        //this one is call 24 time for each for loop
          }


        //my question is in for loop if j=1 set interval 2000 misec
                                        j=2 set interval 2000 misec
                                        j=3 set interval 2000 misec
                                        j=4 set interval 2000 misec
                                        .......................
                                        .......................
                                        ........................
                                        j=n set interval clear



请给出此问题的解决方案



please give this problem soluction

推荐答案

for(var j=1; j<=n;j++)
{
  var intr;       
  if(j==1)
  {
    intr= 2000;
  }
  else if(j==2)
  {
    intr= 2000;
   }
   else if( j == n)
   {
     intr = nnn;
    }
  setInterval(function(){calcRoute(ss,j); alert("time");},intr);

}


这篇关于在javascript中为循环设置间隔时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆