2008-04-22
支持绑定多个函数的onDomReady事件
关键字: javascript, ajax
onDomReady比on load要更好,在Ext,mootools的框架里都有类似的实现。但有时我们并不需要这两个js框架,不能因为一个onDomReady就引入其他js,太浪费了。所以自己写了一个。
在IE6,firefox2上测试通过。
在IE6,firefox2上测试通过。
<script>
(function(){//闭包,保护全局变量
var fns=[];
/**
* onDomReady
*/
window.onDomReady = function(fn) {
fns.push(fn);
}
function runFns(){
for(var i=0;i<fns.length;i++){
fns[i]();
}
}
//W3C
if(document.addEventListener){
document.addEventListener("DOMContentLoaded", runFns, false);
}
else { //IE
document.onreadystatechange = function(){
if(document.readyState == "interactive")
{
runFns();
}
}
}
})();
window.onDomReady(function(){
alert('init 1');
});
window.onDomReady(function(){
alert('init 2');
});
window.onDomReady(function(){
alert('init 3');
});
</script>
- 16:29
- 浏览 (731)
- 评论 (0)
- 分类: html/css/js
- 发布在 javascript研究小组 圈子
- 相关推荐
发表评论
- 浏览: 183889 次
- 性别:

- 来自: 安徽

- 详细资料
搜索本博客
我的相册
分形大厦
共 10 张
共 10 张
最近加入圈子
链接
最新评论
-
Person对象中"姓-名"的 ...
jasongreen 写道都别装了 写道数据库还是叫first / last n ...
-- by 都别装了 -
Person对象中"姓-名"的 ...
我搞不懂的是老外为什么一定要把first name和last name分开,直接 ...
-- by quaff -
Person对象中"姓-名"的 ...
都别装了 写道数据库还是叫first / last name 在页面显示的时候做 ...
-- by jasongreen -
Person对象中"姓-名"的 ...
数据库还是叫first / last name 在页面显示的时候做i18n不就好 ...
-- by 都别装了 -
Person对象中"姓-名"的 ...
e文 显示时候就颠倒下顺序不就得了。。
-- by 叶子






评论排行榜