簡體   English   中英

Javascript 事件在 Firefox 和 IE9

[英]Javascript events in Firefox and IE9

我將我的 ASP.NET 應用附加到上下文菜單上的單元格oncontextmenu string.Format("OnCellContextMenu({0}, '{1}', true, true)", e.VisibleIndex, e.DataColumn.FieldName)

在我的 JS 中,我定義了以下 function。

function OnCellContextMenu(visibleIndex, fieldName, hasNote, hasValue) {
    currentVisibleIndex = visibleIndex;
    currentFieldName = fieldName;

    if (fieldName == "Name" || fieldName == "TOTAL") {
        EnableMenuItem('AddNote', false);
        EnableMenuItem('EditNote', false);
        EnableMenuItem('RemoveNote', false);
    }
    else {
        EnableMenuItem('AddNote', !hasNote && hasValue);
        EnableMenuItem('EditNote', hasNote);
        EnableMenuItem('RemoveNote', hasNote);
    }

    window.event.returnValue = false;

    gvPrevisions.SetFocusedRowIndex(visibleIndex);
    GridMenu.ShowAtPos(ASPxClientUtils.GetEventX(event), ASPxClientUtils.GetEventY(event));
}

現在,在 IE 上工作正常,但在 Firefox window.event.returnValue = false; 它沒有被執行。 我在谷歌上搜索了一下 Firefox 是如何處理這個返回值的,我知道我應該調用e.preventDefault(); 插入 window.event。 問題是在我的 function 中e是未定義的。

你能幫我找到一個同時適用於 FF 和 IE 的解決方案嗎?

謝謝

您可以重構您的代碼以使用 jQuery,它適用於所有瀏覽器 例如:

$('body').bind('contextmenu', function(e) {
    //Stop browser from opening context menu
    e.preventDefault();
    //Do more stuff
});

我找到了出路。

我以這種方式聲明了 function:

function OnCellContextMenu(e, visibleIndex, fieldName, hasNote, hasValue)

和這樣的協會:

e.Cell.Attributes.Add("oncontextmenu", string.Format("OnCellContextMenu(event, {0}, '{1}', true, true)", e.VisibleIndex, e.DataColumn.FieldName));

然后在 function 中我得到了var currentEvent = (window.event)? window.event: e; var currentEvent = (window.event)? window.event: e; 並在其他 function 調用中使用currentEvent ,例如ASPxClientUtils.PreventEventAndBubble(currentEvent);

干杯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM