【问题标题】:asp.net button click event not working with firefoxasp.net 按钮单击事件不适用于 Firefox
【发布时间】:2010-07-19 13:19:57
【问题描述】:

以下是我正在使用的代码。它在 IE 中工作,但在 firefox 中未正确生成按钮单击事件:

function trapEnter(btn,hdn, event) {
    var key;
    var isIE = true;
    debugger;
    if (window.event) {
        key = window.event.keyCode;     //IE
        isIE = true;
    }
    else {
        key = event.which;      //firefox
        isIE = false;
    }
    if (key == 13) {

    var btn = document.getElementById(btn);
    if (btn != null) { //If we find the button click it
        document.getElementById(hdn).value = '1'
        btn.click();

        key = 0;
    }
}

}

【问题讨论】:

标签: asp.net button click


【解决方案1】:

我认为你的函数有错误的参数。试试这个:

function trapEnter(e) {
  e = e || window.event || event;
  var code = e.charCode || e.keyCode || e.which;
  if (code == 13) {
    var btn = document.getElementById('<%= YourButtonID.ClientID %>');
    if (btn != null) { //If we find the button click it
        document.getElementById(hdn).value = '1';
        btn.click();

        key = 0;
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    • 2021-09-13
    • 1970-01-01
    • 1970-01-01
    • 2016-05-13
    • 2013-05-14
    相关资源
    最近更新 更多