禁用文本框的上下文菜单

问题描述 投票:0回答:1

我有一个自定义文本框控件,它扩展了 TextBox APS.NET 类。它的构建使得右键单击时会打开日历。到目前为止一切顺利,但在 Firefox 中,默认上下文菜单会在我的日历控件上打开,如下所示:

。我想知道如何禁用此 Firefox 内容菜单并防止其出现。

我尝试在 JavaScript document.oncontextmenu = function() {return false;} 中进行设置,但这将禁用我页面上的所有上下文菜单。我在该控件内打开日历的代码是:

if (isDate) // check if it's a date textbox where the calendar should be displayed on right click
{
   this.Attributes.Add("oncontextmenu", "javascript:ShowCalendar(this);");
 }

我认为我需要以某种方式在此处设置它以防止打开其他上下文菜单,但我不确定如何设置。非常感谢任何建议。

javascript asp.net contextmenu
1个回答
0
投票

找到了解决方案。我应该调用 event.stop() 来防止上下文菜单出现在我的日历上。

this.Attributes.Add("oncontextmenu", "javascript:if(event.stop) {event.stop();} ShowCalendar(this);");

无论如何谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.