标签:on() event als 常用事件 事件 function window div false
1 var eventUtil={ 2 // 添加句柄 3 addHandler:function(element,type,handler){ 4 if(element.addEventListener){ 5 element.addEventListener(type,handler,false); 6 }else if(element.attachEvent){ 7 element.attachEvent(‘on‘+type,handler); 8 }else{ 9 element[‘on‘+type]=handler; 10 } 11 }, 12 // 删除句柄 13 removeHandler:function(element,type,handler){ 14 if(element.removeEventListener){ 15 element.removeEventListener(type,handler,false); 16 }else if(element.detachEvent){ 17 element.detachEvent(‘on‘+type,handler); 18 }else{ 19 element[‘on‘+type]=null; 20 } 21 }, 22 getEvent:function(event){ 23 return event?event:window.event; 24 }, 25 getType:function(event){ 26 return event.type; 27 }, 28 getElement:function(event){ 29 return event.target || event.srcElement; 30 }, 31 preventDefault:function(event){ 32 if(event.preventDefault){ 33 event.preventDefault(); 34 }else{ 35 event.returnValue=false; 36 } 37 }, 38 stopPropagation:function(event){ 39 if(event.stopPropagation){ 40 event.stopPropagation(); 41 }else{ 42 event.cancelBubble=true; 43 } 44 } 45 }
标签:on() event als 常用事件 事件 function window div false
原文地址:http://www.cnblogs.com/dream-to-pku/p/6048597.html