我想在一个while
循环内添加延迟/休眠:
我尝试像这样实现:
alert('hi');
for(var start = 1; start < 10; start++) {
setTimeout(function () {
alert('hello');
}, 3000);
}
只有第一种情况是正确的:显示 alert('hi')
后,它将等待3秒钟,然后显示 alert('hello')
,但随后 alert('hello')
将不断地重复显示。
我希望的是,在显示 alert('hi')
之后3秒钟后显示 alert('hello')
,然后再等待3秒钟显示第二次 alert('hello')
,以此类推。