1 // 扩浏览器的事件添加删除程序 2 var EventUtil = { 3 addHandler: function(element,type,handler){ 4 if(element.addEventListener){ 5 element.addEventListener(type,handler,false); 6 }else if(element.attachEvent){ 7 element.addachEvent("on"+type,handler); 8 }else{ 9 element["on"+type]=handler; 10 } 11 }, 12 removeHandler:function(element,type,handler){ 13 if(element.removeEventListener){ 14 element.removeEventListener(type, handler,false); 15 }else if(element.detachEvent){ 16 element.detach("on"+type,handler); 17 }else{ 18 element["on"+type]=null; 19 } 20 }, 21 getEvent:function(event){ 22 return event ? event : window.event; 23 }, 24 getTarget:function(event){ 25 return event.target ? event.target : event.srcElement; 26 }, 27 preventDefault:function(event){ 28 if(event.preventDefault()){ 29 event.preventDefault(); 30 }else{ 31 event.returnValue=false; 32 } 33 }, 34 stopPropagation: function(event){ 35 if (event.stopPropagation){ 36 event.stopPropagation(); 37 } else { 38 event.cancelBubble = true; 39 } 40 } 41 }