var eventUtil = { // 添加句柄 addHandler:function(element,type,handler){ if(element.addEventListener){ element.addEventListener(type,handler,false); }else if(element.attachEvent){ element.attachEvent('on'+type,handler); }else{ element['on'+type]=handler; } }, // 删除句柄 removeHandler:function(element,type,handler){ if(element.removeEventListener){ element.removeEventListener(type,handler,false); }else if(element.detachEvent){ element.detachEvent('on'+type,handler); }else{ element['on'+type]=null; } } } showMes4(){ alert("跨浏览器的click事件"); } eventUtil.addHandler(btn5,'click',showMes4);
body部分
<input type="button" id="btn5" value="按钮5"><br/>
showMes4( )前面加function