先记录一下,代码解释以后添上。
1 1 var EventUtil={ 2 2 addHandler:function(element,type,handler){ 3 3 if(element.addEventListener){ 4 4 element.addEventListener(type,handler,false); 5 5 }else if(element.attachEvent){ 6 6 element.attachEvent("on"+type,handler); 7 7 }else { 8 8 element["on"+type]=handler; 9 9 } 10 10 }, 11 11 removeHandler:function(element,type,handler){ 12 12 if(element.removeEventListener){ 13 13 element.removeEventListener(type,handler,false); 14 14 }else if(element.detachEvent){ 15 15 element.detachEvent("on"+type,handler); 16 16 }else{ 17 17 element["on"+type]; 18 18 } 19 19 }, 20 20 getEvent:function(event){ 21 21 return event?event:window.event ; 22 22 }, 23 23 getTarget:function(event){ 24 24 return event.target||event.srcElement ; 25 25 }, 26 26 preventDefault:function(event){ 27 27 if(event.preventDefault){ 28 28 event.preventDefault(); 29 29 }else { 30 30 event.returnValue =null; 31 31 } 32 32 }, 33 33 atopPropagation:function(event){ 34 34 if(event.atopPropagation){ 35 35 event.atopPropagation(); 36 36 }else { 37 37 event.cancelBubble =true; 38 38 } 39 39 } 40 40 };