let divBox = document.querySelector('#workspace_row-grid'); //事件委托 给对应的元素列表绑定事件
divBox.addEventListener('mouseover', function(e){
let target = e.target || e.srcElement
let className = target.className.toLowerCase()
if (!!target && (className == 'workspace_row-apps-item' || className == 'workspace_row-apps-item-name'))//获取对应的列表元素 {
console.log(target)
target.oncontextmenu = function(e) {//鼠标右键事件绑定
console.log(e)
e.preventDefault();
}
}
})
列表元素事件委托绑定鼠标右键事件
最新推荐文章于 2024-03-03 21:38:39 发布
本文介绍了如何通过事件委托技术,实现在工作区的 apps-item 或 apps-item-name 上绑定鼠标右键事件,以便在特定元素上执行定制操作。
599

被折叠的 条评论
为什么被折叠?



