我尝试每2秒输出一个带有消息“hello”的警告框,但只有5次。所以我写了这样的代码:setTimeout在做while while循环时
var counter = 1;
do {
setTimeout
(
function()
{
alert("hello");
counter++;
},
2000
);
} while(counter <= 5);
但是我的页面每次都会崩溃?为什么? 在警报之间添加2000ms延迟的最佳方式是什么?
的可能的复制[是否有可能在Javascript链setTimeout的功能是什么?(http://stackoverflow.com/问题/ 6921275/is-it-it-it-it-it-it-ita-set-out-functions-in-javascript) – smnbbrv