js 去掉瀏覽器右擊默認事件


1.整個頁面所有的右擊事件

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

 

2.特定的區域

document.getElementById("test").oncontextmenu = function(e){
  return false;
}

 

3.去掉后可以給喜歡區塊加特定的事件

js:

document.getElementById("test").onmousedown = function(e){
  if(e.button ==2){
    alert("你點了右鍵");
  }else if(e.button ==0){
    alert("你點了左鍵");
  }else if(e.button ==1){
    alert("你點了滾輪");
  }
}

jq:

$("#test").mousedown(function(e){
  //doing
});

 

4.通過jq  bind 綁定 和 觸發

$('').bind("contextmenu",function (e){

   //doning

   return false;

});

$('').trigger('contextmenu');


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM