如何在JavaScript循环中添加延迟?
我想在while循环中添加延迟/睡眠:
我试过这样的:
alert('hi');for(var start = 1; start < 10; start++) {
setTimeout(function () {
alert('hello');
}, 3000);}只有第一种情况是真的:显示后alert('hi'),它将等待3秒然后alert('hello')将显示,但随后alert('hello')将反复不断。
我想要的是,在alert('hello')3秒后显示alert('hi')之后,它需要等待第二次3秒alert('hello'),依此类推。
慕森卡
开满天机
慕哥6287543
翻阅古今
随时随地看视频慕课网APP