-
Notifications
You must be signed in to change notification settings - Fork 895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Day386:写一个通用的事件侦听器函数 #1221
Comments
`export const myEvent = { }` |
let eventUtils = {
addEventListener:(ele,type,handler)=>{
if(ele.addEventListener){
ele.addEventListener(type,handler)
} else if(ele.attachEvent){
ele.attachEvent("on"+type,handler)
} else {
ele['on'+type] = handler
}
},
removeEventListener:(ele,type,handler)=>{
if(ele.addEventListener){
ele.removeEventListener(type,handler)
} else if(ele.attachEvent){
ele.detachEvent("on"+type,handler)
} else {
ele['on'+type] = null
}
}
} |
`const EventUtils = { // 移除事件 // 获取事件目标 // 获取 event 对象的引用,取到事件的所有信息,确保随时能使用 event // 阻止事件(主要是事件冒泡,因为 IE 不支持事件捕获) // 取消事件的默认行为 |
扫描下方二维码,收藏关注,及时获取答案以及详细解析,同时可解锁800+道前端面试题。
The text was updated successfully, but these errors were encountered: