Backspace key issue in firefox

后端 未结 2 1074
情书的邮戳
情书的邮戳 2021-01-12 11:26

I have an text box and applied Allow Alphabets With Space only using jquery. Its working in chrome But in firefox the backspace key is not working.



        
2条回答
  •  一个人的身影
    2021-01-12 12:12

    This should work in all [major] browsers:

    $('#id1').keydown(function (event) {
        if (event.which == 8) {
            // ...
        } else {
            event.preventDefault();
        }
    );
    

    Note the use of keydown instead of keypress, which is essential for it to work.

提交回复
热议问题