Why isn't backspace being detected using jquery keypress event?

前端 未结 3 1991
醉酒成梦
醉酒成梦 2020-12-30 00:42

Why isn\'t backspace being detected using jquery keypress event?

$(\"#field\").keypress(function(event){alert(event.which);});
相关标签:
3条回答
  • 2020-12-30 00:51

    Try using keydownand keyupfunctions instead for IE.

    Javascript e.keyCode doesn't catch Backspace/Del in IE

    0 讨论(0)
  • 2020-12-30 01:12

    The onKeyUp alone will do all the keyboard key detection in chrome..

    0 讨论(0)
  • 2020-12-30 01:18

    The "keypress" event is (in its original IE form, and in Safari/Chrome) about an actual character being added to a text field. The backspace key clearly does not add a new character to the field value, so it causes no keypress event.

    Firefox and Opera are a little more willy-nilly about generating typing events.

    PPK (quirksmode) considers the IE and Webkit behaviors to be the sensible ones, and I pretty much agree.

    0 讨论(0)
提交回复
热议问题