Javascript sleep 函數

此函數僅適合在10秒內 sleep(5) 超過10秒CPU 會吃不消javascript

<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>
相關文章
相關標籤/搜索