开发者

asp.net button click event not working with firefox

Following is the code that i am using. It work in IE but the button click event is not generated properly in 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 != 开发者_Go百科null) { //If we find the button click it
        document.getElementById(hdn).value = '1'
        btn.click();

        key = 0;
    }
}

}


I think your function has the wrong parameters. Try this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜