事件偵聽函式
阿新 • • 發佈:2020-07-24
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 } } }