2012-02-22 3 views
2

J'ai un simple jquery un code de touche qui détecte lorsque l'utilisateur tape la touche @. Le problème: Fonctionne très bien dans webkit (Chrome/Safari) mais ne fait absolument rien dans FF.jQuery @ détection Keypress dans Firefox

Le violon JS: http://jsfiddle.net/cUzzt/

Le code:

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

Répondre

7

Vous voulez charCode:

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

Wow. C'était facile! – Adam

+0

http://whatkey.net/keypress vous aidera à trouver tout –