一、定义
//第一种,使用while循环 function sleep(delay) { var start = (new Date()).getTime(); while((new Date()).getTime() - start < delay) { continue; } } //或者使用for循环 function sleep(delay) { for(var t = Date.now(); Date.now() - t <= d;); }
二、使用
this.sleep(1000); //延时1秒
标签:function,getTime,前端,javascript,delay,sleep,Date From: https://www.cnblogs.com/StarZhai/p/16591854.html