跨浏览器的事件对象EventUtil
var EventUtil = function(){ /*--addHandler--*/ addHandler:function(element,type,handler){ if(element.addEventListener){ element.addEventListener(type,handler,false); }else{ element.attachEvent(‘on’+type,handler); } }, /*--getEvent--*/ getEvent:function(event){ return event?event:window.event; }, /*--getTarget--*/ getTarget:function(event){ return event.target || event.srcElement; }, /*--preventDefault--*/ preventDefault:function(event){ if(event.preventDefault){ event.preventDefault(); }else{ event.returnValue = false; } }, /*--removeHandler--*/ removeHandler:function(){ if(element.removeEventListener){ element.removeEventListener(type,handler,false); }else{ element.detachEvent(‘on’+type,handler); } }, /*--stopPropagation--*/ stopPropagation:function(){ if(event.stopPropagation){ event.stopPropagation(); }else{ event.cancelBubble = true; } } }