2010-12-10 54 views

回答

1

你是说像this? (当你按下TAB键和重点是页面上的任何地方它的警报)

$(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; 
    } 
    }); 
}); 

请不要破坏你的用户体验:使用你的权力是好是真棒。