不使用setTimeout的延迟执行

Posted on 2021-09-29 19:37  小小憨批儿  阅读(155)  评论(0编辑  收藏  举报
function sleep(ms){
    var time = new Date();
    time.setTime(time.getTime() + ms);
    while(new Date().getTime() < time.getTime());
}

window.onload = function(){
    sleep(5000);
    alert('啊哈!');
}

Copyright © 2024 小小憨批儿
Powered by .NET 9.0 on Kubernetes