等页面加载完再加载js 页面加载完成后等待一段时间在执行js的方法,时间如何设定?
页面加载完成后等待一段时间在执行js的方法,时间如何设定?例如:function test(){return 1}页面加载完成事件:window.onload文件=Function(){setTime
页面加载完成后等待一段时间在执行js的方法,时间如何设定?
例如:function test(){return 1}页面加载完成事件:window.onload文件=Function(){setTimeout(test,1000)//1000ms=executetestmethodafter1second}如果使用jQuery,可以:$(window)。Load(function(){SetTimeout(test,1000)//1000 ms=execute the test method after 1秒})SetTimeout只执行一次并重复执行setIntervalwindow.onload=Function(){setinterval(test,1000)//1000ms=1s,每隔1s执行一次test方法}