代码出于js高级编程 1. [代码] [JavaScript]代码 var EventUtils={ addHandler:function(elem,type,func) { if(elem.addEventListener) { elem.addEventListener(type,func,false); }else if(elem.attachEvent) { elem.attachEvent("on"+type,fun
1. [代码][JavaScript]代码
var EventUtils={ addHandler:function(elem,type,func) { if(elem.addEventListener) { elem.addEventListener(type,func,false); }else if(elem.attachEvent) { elem.attachEvent("on"+type,func); } else{ elem["on"+type]=func; } }, getEvent:function(event){ return event?event:window.event; }, getTarget:function(event){ return event.target||event.srcElement; }, preventDefault:function(event){ if(event.preventDefault) { event.preventDefault(); } else{ event.returnValue=false; } }, stopPropagation:function(event){ if(event.stopPropagation){ event.stopPropagation(); } else{ event.cancelBubble=true; } }, removeHandler:function(elem,type,func){ if(elem.removeEventListener) { elem.removeEventListener(type,func,false); }else if(elem.detachEvent) { elem.detachEvent("on"+type,func); } else { elem["on"+type]=null; } } };