HTML text input allow only numeric input

前端 未结 30 4314
孤街浪徒
孤街浪徒 2020-11-21 04:58

Is there a quick way to set an HTML text input () to only allow numeric keystrokes (plus \'.\')?

30条回答
  •  佛祖请我去吃肉
    2020-11-21 05:36

    I've searched long and hard for a good answer to this, and we desperately need , but short of that, these 2 are the most concise ways I could come up with:

    
    

    If you dislike the non-accepted character showing for a split-second before being erased, the method below is my solution. Note the numerous additional conditions, this is to avoid disabling all sorts of navigation and hotkeys. If anyone knows how to compactify this, let us know!

    
    

提交回复
热议问题