Javascript sleep 函数

此函数仅适合在10秒内 sleep(5) 超过10秒CPU 会吃不消

<script type="text/javascript">
function sleep(seconds) {
    this.date = Math.round(new Date().getTime()/1000);
    while(1) {
        if(Math.round(new Date().getTime()/1000) - this.date >= seconds) break;
    }
    return true;
}
sleep(5);
alert(1);
</script>

 

posted on 2013-12-26 15:49  小东北  阅读(1499)  评论(0编辑  收藏  举报