简体   繁体   中英

ASP.NET - onkeydown event not working in Firefox

So I am having an issue in Firefox with the onkeydown event for an image button. I don't want the button action to fire until they let up off the button. So this works great in both IE and Chrome. I cannot figure out why it doesn't work in Firefox(20.0.1). Here is the image button code:

<asp:ImageButton ID="btnButton1" ImageUrl="/images/target.png" runat="server" 
Height="75" Width="75" onkeydown="return false;" onkeyup="ButtonClick()" />

So the onkeyup seems to work perfect in all browsers, but the onkeydown does not want to work in Firefox and I cannot figure it out. Any help would be greatly appreciated.

I don't know if it will help, but I will post my JavaScript function for onkeyup as well:

 function ButtonClick() {
    document.getElementById('<%=btnButton1.ClientID %>').click();
    return true;
}

hmmm, you can try?

$(document).on("keypress", ".chat-input ", function (val) {
    clearTimeout(timer);
    timer = setTimeout(function () {
      //codes
    }, 1);
}).on('keydown', function (e) {
    if (e.keyCode == 8 || e.keyCode == 13) {
        $('.chat-input').trigger('keypress');
    }
});

please try using

function ButtonClick() {
    document.getElementById('<%#btnButton1.ClientID %>').click();
    return true;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM