Firefox中的jQuery @ Keypress检测

Ada*_*dam 2 javascript firefox jquery keypress

我有一个简单的jquery按键代码,用于检测用户何时键入@键.问题:在webkit(Chrome/Safari)中运行良好,但在FF中绝对没有.

JS小提琴:http://jsfiddle.net/cUzzt/

代码:

$(document).ready(function(){
    $(document).keypress(function(e) {
          if(e.keyCode == 64) { //@ Symbol
              alert("You pressed the @ key");
          }
    });
});
Run Code Online (Sandbox Code Playgroud)

glo*_*tho 7

你想要charCode:

$(document).ready(function(){
    $(document).keypress(function(e) {
          if(e.charCode == 64) { //@ Symbol
              alert("You pressed the @ key");
          }
    });
});
Run Code Online (Sandbox Code Playgroud)