js禁止右鍵

禁止右鍵菜單一搜就有了,下面代碼是禁止右鍵事件,可以根據event的which或者bottun進行判斷禁止

$('#11').mousedown(function(e){
    if(3 == e.which){// or e.bottun===2
        console.log('這是右鍵單擊事件');
    }else if(2 == e.which){//or e.bottun === 1
        console.log('這是中鍵單擊事件');
    }else(1 == e.which){//or e.button===0
        console.log('這是左鍵單擊事件');
    }
})
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章