事件侦听函数
作者:互联网
const EventUtils = { addEnent(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 } }, removeEvent(elemnet,type,handler){ if(element.removeEventListener){ element.removeEventListener(type.handler,false) }else if(element.detachEvent){ element.detachEvent(`on${type}`,handler) }else{ element[`on${type}`] = null } }, getTarget(event){ return event || window.event }, stopPropagation(event){ if(event.stopPropagation){ event.stopPropagation() }else{ event.cancelBubble = true } }, preventDefault(event){ if(event.preventDefault){ event.preventDefault() }else{ event.returnValue = false } } }
标签:函数,侦听,preventDefault,element,handler,事件,else,type,event 来源: https://www.cnblogs.com/zhenjianyu/p/13374641.html