asp.net按钮单击事件不能与Firefox一起使用

时间:2010-07-19 13:19:57

标签: asp.net button click

以下是我正在使用的代码。它在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;
    }
}

}

1 个答案:

答案 0 :(得分:0)

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

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;
    }
  }
}