我想在while循环中添加延迟/睡眠:
我试过这样的:
alert('hi');
for(var start = 1; start < 10; start++) {
setTimeout(function () {
alert('hello');
}, 3000);
}
Run Code Online (Sandbox Code Playgroud)
只有第一种情况是真的:显示后alert('hi'),它将等待3秒然后alert('hello')将显示,但随后alert('hello')将反复不断.
我想要的是,在alert('hello')3秒之后显示alert('hi')之后,它需要等待第二次3秒alert('hello'),依此类推.
有没有类似于jQuery的JavaScript方法delay()或wait()(在特定时间内延迟执行脚本)?