How can I disabling backspace key press on all browsers?

后端 未结 9 1152
一向
一向 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:37

    Instead of keypress, try the keydown function, it will fire before the actual browser based hook. Also, putting in a preventDefault() function will assist in this. IE :

    $(document).keydown(function(e){
       e.preventDefault();
       alert(e.keyCode);
    });
    

    Hope this helps.

提交回复
热议问题