How to allow numbers, backspace, delete, left and right arrow keys in the html text?

前端 未结 5 2034
野趣味
野趣味 2021-02-05 06:25

I am using following javascript code which I think should only allow numbers, backspace, delet, left arrow and right arrow keys in textbox, but it is also allowing alphabets. I

5条回答
  •  逝去的感伤
    2021-02-05 07:06

          function isNumberKey(evt)
          {
             var charCode = (evt.which) ? evt.which : event.keyCode
             if (charCode > 31 && (charCode < 48 || charCode > 57))
                return false;
             return true;
          }
    
       
       
       
          
       
    

提交回复
热议问题