首页 > 其他分享 >原生JS 绑定右键菜单 并隐藏浏览器右键菜单

原生JS 绑定右键菜单 并隐藏浏览器右键菜单

时间:2024-04-22 16:35:04浏览次数:15  
标签:style 菜单 浏览器 menu JS 右键 var

原生JS 绑定右键菜单 并隐藏浏览器右键菜单

 //获取元素
 var dom = document.getElementById("box");
 dom.addEventListener('contextmenu', function(e) {
   if (e.button === 2){
      notesTitle=e.srcElement.innerText // 获取点击的元素
      e.preventDefault();// 取消浏览器右键菜单
      // 跟随鼠标
      var x = e.clientX;
      var y = e.clientY;
      var menu = document.querySelector('#note_list_menu');
      menu.style.left = x + 'px';
      menu.style.top = y + 'px';
      menu.style.display = 'block';
      // 鼠标点击其他位置时隐藏菜单
      document.onclick = function(){
         menu.style.display = 'none';
      }
    }
   });

标签:style,菜单,浏览器,menu,JS,右键,var
From: https://www.cnblogs.com/qx-blog/p/18150870

相关文章

  • Node.js数电票、全电票查验接口示例、发票查验、票据OCR API
    何为数电票:数电票全称为全面数字化的电子发票,是一种全新的发票形式,与传统的纸质发票具有同等的法律效力,以数字形式存在,不依赖于纸质介质,而数电票的推行旨在提高发票管理效率,降低企业成本,推动税收征管的现代化进程。发票查验的自动化和智能化管理,可以显著减少人工核对发票......
  • Node.js身份核验接口、身份证二、三要素实名认证接口
    随着互联网的高速发展,人们可以发表言论的渠道越来越多。网络平台不断汲取各地、各人、各时发表的各种信息。人们喜欢将信息发布到微博、知乎、天涯、豆瓣等等网络平台,逐步的,网络信息进入大爆炸时代。这些大量涌现的信息中难免掺杂着一些不良信息,比如:虚假信息、污言秽语、违法......
  • vue.js 3 上传文件:el-upload 组件
    "@element-plus/icons-vue":"^2.3.1","axios":"^1.6.8","element-plus":"^2.6.2","pinia":"^2.1.7","pinia-plugin-persistedstate":"^3.2.1","vue":&......
  • vis.js分组并排条形图
    代码案例<!doctypehtml><html><head><title>Timeline</title><scripttype="text/javascript"src="https://unpkg.com/vis-timeline@latest/standalone/umd/vis-timeline-graph2d.min.js"></script>......
  • vis.js并排条形图
    代码案例<!doctypehtml><html><head><title>Timeline</title><scripttype="text/javascript"src="https://unpkg.com/vis-timeline@latest/standalone/umd/vis-timeline-graph2d.min.js"></script>......
  • vis.js条形图(2)
    代码案例<!doctypehtml><html><head><title>Timeline</title><scripttype="text/javascript"src="https://unpkg.com/vis-timeline@latest/standalone/umd/vis-timeline-graph2d.min.js"></script>......
  • vis.js自定义轴
    代码案例<!doctypehtml><html><head><title>Timeline</title><scripttype="text/javascript"src="https://unpkg.com/vis-timeline@latest/standalone/umd/vis-timeline-graph2d.min.js"></script>......
  • vis.js条形图
    代码案例<!doctypehtml><html><head><title>Timeline</title><scripttype="text/javascript"src="https://unpkg.com/vis-timeline@latest/standalone/umd/vis-timeline-graph2d.min.js"></script>......
  • js数组转成树形结构
    js将数组转成对应的树形结构:functiontransformArrayToObject(array){ constresult={}; array.forEach(item=>{ const{ id, name, pid, flag }=item; if(pid==0){ result[name]={ id, flag, pid } }else{ transfo......
  • input js 只能输入数字和两位小数
    functiononlyNumber(obj){//得到第一个字符是否为负号vart=obj.value.charAt(0);//先把非数字的都替换掉,除了数字和.和-号obj.value=obj.value.replace(/[^\d\.]/g,'');//前两位不能是0加数字obj.value=obj.value.replace(/^0\d[0-9]*/g,'');......