2010-12-10 3 views

답변

1

문서의 몸에 keypress 이벤트를 사용할 수 있습니까? 좋은 또는 최고에 대한 귀하의 능력을 사용 :

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

사용자 환경을 파괴하지 마십시오 (Tab 키를 누르면 초점이 페이지의 아무 곳이나 때이 경고를 않습니다).

관련 문제