$(document).on(“keypress” - 未在Firefox中触发

时间:2015-11-30 10:07:23

标签: javascript jquery firefox browser keypress

代码:

$(document).on("keypress", ".className", function (e) {
     debugger;
     if (e.which == 13) {
     debugger;
           ....
           ...
    }
}

以上代码触发IECHROME 无效 FIREFOX

注意: 我已经引用了与此相关的以下SO链接,但没有任何东西可以让firefox触发..

onKeyPress event not working in Firefox

Key press event is not working in Mozilla Firefox

keypress is not working in Mozila Firefox

1 个答案:

答案 0 :(得分:0)

您应该在Firefox中使用e.charCode

$(document).on("keypress", ".className", function (e) {
     var code = e.charCode || e.keyCode;
     if (code == 13) {
     debugger;
           ....
           ...
    }
});