首页 > 代码库 > 页面全部加载完毕和页面dom树加载完毕

页面全部加载完毕和页面dom树加载完毕

dom树加载完毕

$(document).ready()

//原生写法
document.ready = function (callback) {
            ///兼容FF,Google
            if (document.addEventListener) {
                document.addEventListener(‘DOMContentLoaded‘, function () {
                    document.removeEventListener(‘DOMContentLoaded‘, arguments.callee, false);
                    callback();
                }, false)
            }
             //兼容IE
            else if (document.attachEvent) {
                document.attachEvent(‘onreadytstatechange‘, function () {
                      if (document.readyState == "complete") {
                                document.detachEvent("onreadystatechange", arguments.callee);
                                callback();
                       }
                })
            }
            else if (document.lastChild == document.body) {
                callback();
            }
        }

页面全部(包括图片)加载完毕

$(window).load()

//原生
window.onload=function(){
}

 

页面全部加载完毕和页面dom树加载完毕