【问题标题】:jQuery @ Keypress detection in FirefoxFirefox 中的 jQuery @ Keypress 检测
【发布时间】:2012-02-22 01:47:21
【问题描述】:

我有一个简单的 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");
          }
    });
});

【问题讨论】:

    标签: javascript jquery firefox keypress


    【解决方案1】:

    你想要charCode:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-23
      • 1970-01-01
      • 2012-12-29
      • 2011-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多