Javascript 如何为某些元素启用上下文菜单
我已禁用文档的上下文菜单(鼠标右键单击)。 $(document.bind('contextmenu',function(){return false;}); 现在我想为某些输入启用上下文菜单。 $('#昵称').bind('contextmenu',function(){return true;});Javascript 如何为某些元素启用上下文菜单,javascript,jquery,contextmenu,Javascript,Jquery,Contextmenu,我已禁用文档的上下文菜单(鼠标右键单击)。 $(document.bind('contextmenu',function(){return false;}); 现在我想为某些输入启用上下文菜单。 $('#昵称').bind('contextmenu',function(){return true;}); 但它不起作用。有什么想法吗?根据单击的元素,您可以从文档上下文菜单处理程序返回true/false。请参阅事件的.target属性 $(document).bind('contextmenu',
但它不起作用。有什么想法吗?根据单击的元素,您可以从文档上下文菜单处理程序返回true/false。请参阅
事件的.target
属性
$(document).bind('contextmenu',function(event){
if (event.target == document.querySelector("#nickname")) {
return true;
} else {
return false;
}
});
请参阅完整示例:
尝试console.log(event)
当不确定如何处理事件时,这里有很多有用的属性