How can I disabling backspace key press on all browsers?

后端 未结 9 1149
一向
一向 2020-12-15 10:01

I\'m trying to disable the backspace button on an order page in all cases except when a textarea or text input is an active element to prevent users from accidentally backin

9条回答
  •  南笙
    南笙 (楼主)
    2020-12-15 10:36

    Use e.which instead of e.keyCode; jQuery normalizes this value across browsers.

    http://api.jquery.com/keydown/

    To determine which key was pressed, examine the event object that is passed to the handler function. While browsers use differing properties to store this information, jQuery normalizes the .which property so you can reliably use it to retrieve the key code.

    Then, use e.preventDefault(); to prevent the default behaviour of moving to the previous page.

提交回复
热议问题