当前位置:编程学习 > JS >>

不用document.ready方法


var jb51 =new function() {
dom = [];
dom.isReady = false;
dom.isFunction = function(obj) {
return Object.prototype.toString.call(obj) === "[object Function]";
}
dom.Ready = function(fn) {
dom.initReady();
//如果没有建成DOM树,则走第二步,存储起来一起杀
if (dom.isFunction(fn)) {
if (dom.isReady) {
fn();
//如果已经建成DOM,则来一个杀一个
} else {
dom.push(fn);
//存储加载事件
}
}
}
dom.fireReady = function() {
if (dom.isReady) return;
dom.isReady = true;
for (var i = 0, n = dom.length; i < n; i++) {
var fn = dom[i];
fn();
}
dom.length = 0;
//清空事件
}
dom.initReady = function() {
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded",
function() {
document.removeEventListener("DOMContentLoaded", arguments.callee, false);
//清除加载函数
dom.fireReady();
},
false);
} else {
if (document.getElementById) {
document.write("<script id="ie-domReady" defer='defer'src="//:"></script>");
document.getElementById("ie-domReady").onreadystatechange = function() {
if (this.readyState === "complete") {
dom.fireReady();
this.onreadystatechange = null;
this.parentNode.removeChild(this)
}
};
}
}
}
}

 

补充:网页制作,jquery
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,