3 回答

TA貢獻1846條經驗 獲得超7個贊
jQuery中沒有內置的oncontextmenu事件處理程序,但是您可以執行以下操作:
$(document).ready(function(){
document.oncontextmenu = function() {return false;};
$(document).mousedown(function(e){
if( e.button == 2 ) {
alert('Right mouse button!');
return false;
}
return true;
});
});
基本上,我取消了DOM元素的oncontextmenu事件以禁用瀏覽器上下文菜單,然后使用jQuery捕獲mousedown事件,您可以在事件參數中知道按下了哪個按鈕。
您可以在此處嘗試上述示例。

TA貢獻1836條經驗 獲得超3個贊
該函數返回太早。我在下面的代碼中添加了注釋:
$(document).ready(function(){
$(document).bind("contextmenu",function(e){
return false;
$('.alert').fadeToggle(); // this line never gets called
});
});
嘗試將換成return false;下一行。

TA貢獻1876條經驗 獲得超5個贊
我在這里找到了這個答案,我正在像這樣使用它。
來自我的圖書館的代碼:
$.fn.customContextMenu = function(callBack){
$(this).each(function(){
$(this).bind("contextmenu",function(e){
e.preventDefault();
callBack();
});
});
}
頁面腳本中的代碼:
$("#newmagazine").customContextMenu(function(){
alert("some code");
});
- 3 回答
- 0 關注
- 604 瀏覽
相關問題推薦
添加回答
舉報