事件绑定

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>无标题文档</title>
 6 </head>
 7 
 8 <body>
 9 <input id="btn1" type="button"  value="点击"/>
10 <script>
11 function myEvent(obj,sEvent,fn)
12 {
13     if(obj.attachEvent)
14     {
15         obj.attachEvent('on'+sEvent,fn);    
16     }
17     else
18     {
19         obj.addEventListener(sEvent,fn,false);    
20     };
21 };
22 var oBtn = document.getElementById('btn1');
23 function aa(){alert(1)};
24 function bb(){alert(2)};
25 myEvent(oBtn,'click',aa);
26 myEvent(oBtn,'click',bb);
27 </script>
28 
29 </body>
30 </html>

 

posted @ 2013-08-11 13:56  The0ne  阅读(86)  评论(0编辑  收藏  举报