标签:add event false 元素 prevent tde ati pre style
var EventUtil = { addHandler: function(element,type,handler){//添加事件 if (element.addEventListener) { element.addEventListener(type,handler,false); }else if (element.attachEvent) { element.attachEvent(‘on‘+type,handler); }else { element[‘on‘+type] = handler; } }, getEvent: function(event){//获得事件对象 return event || window.event; }, getTarget: function(event){//获得事件元素 return event.target || event.srcElement; }, preventDefault: function(){//取消默认事件行为 if (event.preventDefault) { event.preventDefault(); }else { event.returnValue = false; } }, removeHandler: function(element,type,handler){//取消事件 if (element.removeEventListener) { element.removeEventListener(type,handler,false) }else if (element.dettchEvent) { element.dettchEvent(‘on‘+type,handler); }else { element[‘on‘+type] = null; } }, stopPropagation: function(event){//取消冒泡机制if (event.stopPropagation) { event.stopPropagation(); }else { event.cancleBubble = true; } } }
首先要用EventUtil.getEvent(event);获得统一的event对象
标签:add event false 元素 prevent tde ati pre style
原文地址:https://www.cnblogs.com/jokes/p/9650627.html