javascript中派发事件

1 <script type="text/javascript">
2 <!--
3 var dispatchEvent=function(obj,event,fun){
4 if(obj.attachEvent)
5 obj.attachEvent(event.indexOf('on')>-1?event:'on'+event,fun);
6 else
7 addEventListener(event.indexOf('on')>-1?event.substring(2):event,fun,false);
8 };
9 window.onload=function()
10 {
11 alert('1');
12 }
13 function testAlert()
14 {
15 alert('2');
16 }
17 dispatchEvent(window,'onload',testAlert);
18 // -->
19   </script>

 

posted on 2009-12-09 12:58  骑驴睡觉  阅读(173)  评论(0编辑  收藏  举报

导航