cursor is jumping when pressing the arrow keys

前端 未结 5 965
日久生厌
日久生厌 2021-01-07 14:26

I have a textbox, where a forbidden character cant be typed. #.

This works, however, when the textbox is filled in with data, and I put the focus on the middle of th

5条回答
  •  天命终不由人
    2021-01-07 15:05

    Have you tried using the keypress event ?

    The documentation warns about possible differences in behavior between platforms.

    In Firefox at least, e.which corresponds to the ascii code of the typed character after transformation :

    $('#txtClient').keypress(function (e) {
        console.log('keypress:', e.which);
        if (e.which == 35) {
            return false;
        }
    });
    

    updated fiddle

提交回复
热议问题