一个页面中多个window.onload事件解决方案
Simple life
posted @ Thu, 13 Aug 2009 04:55:04 +0800
in Javascript
with tags
javascript Onload
, 8262 readers
- window.onload=function(){function1();function2();}
- function addLoadEvent(func){
var oldonload=window.onload;
if(typeof window.onload!='function'){
window.onload=func;
}else{
window.onload=function(){
oldonload();
func();
}
}
}
添加要加载执行的事件:
addLoadEvent(aaa);
addLoadEvent(bbb);
- 因此要想在你的程序中给一个事件指派多个处理过程的话,只要首先判断一下浏览器,然后根据不同的浏览器,选择使用 attachEvent 还是 addEventListener 就可以了。实例如下
if (document.all) {
window.attachEvent('onload', handler1);
window.attachEvent('onload', handler2);
} else {
window.addEventListener('load', handler1, false);
window.addEventListener('load', handler2, false);
}
Thu, 17 Oct 2019 22:16:48 +0800
Thanks for sharing this post. I appreciate it. I really do.
Mon, 24 May 2021 18:43:55 +0800
Pretty good post. I have just stumbled upon your blog and enjoyed reading your blog posts very much. I am looking for new posts to get more precious info. Big thanks for the useful info. 123movie
Sun, 15 May 2022 03:20:26 +0800
You produced some decent points there. I looked on-line for your problem and found most people is going together with using your site. North American Bancard Agent Program
=====================================
I have seen similar about this expression. But it seems your’s is different and best. Selling Credit Card Machines
Tue, 17 May 2022 14:12:09 +0800
As for Morgan Freeman, he was hardly there in the film. 滅之刃