编写延时函数 var sleep = function(time) { var timeOut = new Date().getTime() + parseInt(time, 10); while(new Date().getTime() <= timeOut) {} }; console.log("start"); sleep(3000); // 单位ms console.log("Hello Javascript"); console.log("end") 此函数会对总程序造成阻塞,非必要情况不建议使用。