首页 > 代码库 > domReady方法(dom加载完成执行回调)
domReady方法(dom加载完成执行回调)
var domReady = function( fn ) { var isReady = false, ready = function(){ if(!isReady){ typeof fn === ‘function‘ && fn.call(document); isReady = true; } }, DOMContentLoaded = function() { if ( document.addEventListener ) { document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false ); ready(); } else if ( document.readyState === "complete" ) { document.detachEvent( "onreadystatechange", DOMContentLoaded ); ready(); } }; if ( document.readyState === "complete" ) { setTimeout( ready, 1 ); } else if ( document.addEventListener ) { document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false ); window.addEventListener( "load", ready, false ); } else { document.attachEvent( "onreadystatechange", DOMContentLoaded ); window.attachEvent( "onload", ready ); var top = false; try { top = window.frameElement == null && document.documentElement; } catch(e) {} if ( top && top.doScroll ) { (function doScrollCheck() { if ( !isReady ) { try { top.doScroll("left"); } catch(e) { return setTimeout( doScrollCheck, 50 ); } ready(); } })(); } }};//调用domReady(function(){ alert(this.getElementById(‘div1‘).innerHTML);});
domReady方法(dom加载完成执行回调)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。