首页 > 代码库 > DOMReady

DOMReady

function DOMReady(fn){
    if(document.addEventListener){
        addEvent(document,‘DOMContentLoaded‘,fn);
    }else{
        IEContentLoaded();
    }
    function IEContentLoaded(){
            var d=window.document;
            var done=false;
            var init=function(){
                if(!done) done=true;
                fn();
            }
        (function(){
            try{
                d.documentElement.doScroll("left");
            }catch(e){
                setTimeout(argumens.callee,13);
                return;
            }
            init();
        });
        d.onreadystatechange=function(){
            if(d.readyState==‘complete‘){
                d.onreadystatechange=null;
                init();
            }
        }

    }
}

 

DOMReady