jQuery Event Keypress: Which key was pressed?

后端 未结 24 2151
半阙折子戏
半阙折子戏 2020-11-21 16:48

With jQuery, how do I find out which key was pressed when I bind to the keypress event?

$(\'#searchbox input\').bind(\'keypress\', function(e) {});
         


        
24条回答
  •  春和景丽
    2020-11-21 16:53

    The event.keyCode and event.which are depracated. See @Gibolt answer above or check documentation: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent

    event.key should be used instead

    keypress event is depracated as well: https://developer.mozilla.org/en-US/docs/Web/API/Document/keypress_event

提交回复
热议问题