const eventUtils = { // 绑定事件 addEvent(ele, type, handler){ if(ele.addEventListener{ ele.addEventListener(type, handler, false) }else if(ele.attachEvent){ ele.attachEvent('on'+type, handler) }else{ ele['on'+type] = handler } }, // 移除事件 removeEvent(ele, type, handler){ if(ele.removeEventListener){ ele.removeEventListener() }else if(ele.detachEvent){ ele.detachEvent('on'+type, handler) }else{ ele['on'+type] = null } }, // 获取事件类型 getEvent(event){ return event || window.event }, // 获取目标对象 getTarget(event){ return event.target || event.srcElement }, // 阻止事件冒泡 stopPropagation(event){ if(event.stopPropagation){ event.stopPropagation() }else{ event.cancelBubble() } }, // 阻止事件默认行为 preventDefault(event){ if(event.preventDefault){ event.preventDefault() }else{ event.retunValue = false } } }