cursor is jumping when pressing the arrow keys

前端 未结 5 962
日久生厌
日久生厌 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条回答
  •  Happy的楠姐
    2021-01-07 15:10

    Just prevent the default action on keypress(keydown does not give consistent charCodes):

    $('[id$=txtClient]').keypress(function (e) {
            if (String.fromCharCode(e.which) == '#'){
                e.preventDefault();
            }
    });
    

    This just prevents # and leaves the rest as it is.

    Here you go;)

提交回复
热议问题