javascript - 禁用文本框时如何在 jquery 中禁用此上下文菜单

标签 javascript jquery html css

<分区>

当文本框被禁用时,如何在 jquery 中禁用上下文菜单下方。我的右键单击禁用功能在所有浏览器中都可以正常工作 除了 Firefox。

注意:启用文本框后,右键单击禁用功能在所有浏览器中都可以正常工作。请在此处提供帮助。

我在我的正文标签中尝试了以下代码。但它在 Firefox 中不起作用

oncontextmenu="return false;" 

enter image description here

最佳答案

此代码适用于 firefox:

document.oncontextmenu=disableclick;
function disableclick(event)
{
    event.preventDefault();
    alert("Context Menu Disabled");
    return false;    
}

http://jsfiddle.net/zumk5cta/1/

更新

contextmenu 事件不适用于 firefox 中的禁用元素,这是一个 firefox 行为,解释得很好 here

作为您问题的解决方案,我采纳了 @Endy E 给出的想法在他的回应中here :

html

<span class="inputWrapper">
    <input type="text" disabled />
    <div class="mouseEventTarget"></div>
</span>

CSS

.inputWrapper{
     position:relative;
}
.mouseEventTarget{
     position:absolute; 
     left:0; 
     right:0; 
     top:0; 
     bottom:0; 
     cursor: text
}

javascript

$(document).on('contextmenu', 'input:disabled + .mouseEventTarget',function(e){ 
    return false; 
});

fiddle

关于javascript - 禁用文本框时如何在 jquery 中禁用此上下文菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28105097/

相关文章:

javascript - 如何使用 jQuery 模拟 vclick?

javascript - 在滚动条上隐藏/显示 webkit 滚动条

javascript - 在相同的 <td> 内获取输入

javascript - 如何将php数据传递给kinetic js

javascript - 在 Javascript 中是否可以为 Firebase 提供可选的 Promise?

javascript - 在引导网格中的第 n 个子项之后插入 div

html - 边距顶部和框阴影在 tbody 中不起作用

javascript - 无法从 'C:\Users\syrine\management\node_modules\stylis-plugin-rtl\src\stylis-rtl.ts' 解析源映射

jquery - 使用带有 ajax 加载内容的 jquery Bootstrap 模式时加载 jQuery select2 时出错

javascript - 识别哪个 span 标签触发了 div 中的 javascript 函数