我想在一个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秒钟后,它需要再等待3秒钟才能再次显示alert('hello'),以此类推。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号