oncontextmenu 事件

用户点击鼠标右键时触发并打开上下文菜单

禁用:

document.oncontextmenu = function() {
  return false;
}

 

编辑自定义右键打开菜单

document.oncontextmenu = function() {
  return false;
}
document.body.addEventListener('mousedown',function(e){
  switch(e.button) {
    case 0:
      console.log("鼠标左键")
      break;
    case 1:
      console.log("鼠标中间");
      break;
    case 2:
      document.getElementById('custom-menu').style.display = 'block'
      console.log("鼠标右键");
      break;
    default:
      break;
  }
})

posted @ 2018-09-14 11:50  卑面派对  阅读(332)  评论(0编辑  收藏  举报