简单的javascript控制台日志(FireFox)

时间:2010-06-15 21:15:18

标签: javascript firefox

我正在尝试在控制台中记录值的更改(Firefox / Firefly,mac)。

 if(count < 1000)
 {
  count = count+1;
  console.log(count);
  setTimeout("startProgress", 1000);
 }

这只返回值1.在此之后停止。

我做错了什么或有其他影响这个的事情吗?

3 个答案:

答案 0 :(得分:10)

你没有循环。只有条件声明。使用while

var count = 1;
while( count < 1000 ) {
      count = count+1;
      console.log(count);
      setTimeout("startProgress", 1000); // you really want to do this 1000 times?
}

更好:

var count = 1;
setTimeout(startProgress,1000); // I'm guessing this is where you want this
while( count < 1000 ) {
    console.log( count++ );
}

答案 1 :(得分:1)

我认为你正在寻找while循环:

var count = 0;
while(count < 1000) {
  count++;
  console.log(count);
  setTimeout("startProgress", 1000);
}

答案 2 :(得分:1)

正如其他答案所示,ifwhile是您的问题。但是,更好的方法是使用setInterval(),如下所示:

setinterval(startProcess, 1000);

这不会停止在1000次通话,但我假设你现在只是为了测试目的而这样做。如果您确实需要停止这样做,可以使用clearInterval(),如下所示:

var interval = setinterval(startProcess, 1000);
//later...
clearInterval(interval);
相关问题