2010-12-10 5 views

Répondre

1

Tu veux dire comme this? (Il fait une alerte lorsque vous appuyez sur la touche TAB et l'accent est mis partout sur la page)

$(document).keypress(function(event) { 
    if (event.keyCode == 9) //TAB key 
    { 
     alert('this is the tab key!'); 
    } 
}); 
1
jQuery(function($){ 
    $(window).keypress(function(e){ //alternatively look up the keydown and keyup functions 
    switch (e.which) 
    { 
     case 13: //whatever key code you want to check for 
     { 
     //do stuff 
     } return false; //prevent propagation of keypress event 
     default: 
     { 
     //log the keycode to console so you can figure out which key is which 
     //there are a number of tables of keycodes available online. 
     if (window.console) console.log(e.which); 
     } break; 
    } 
    }); 
}); 

S'il vous plaît ne pas détruire votre expérience utilisateur: utiliser vos pouvoirs pour le bien ou pour génial.

Questions connexes