Disable zero as first letter in <input>

前端 未结 7 1327
無奈伤痛
無奈伤痛 2021-02-08 19:51

Below code disables 0 as the first character in #foo.
However, you can bypass this by typing 123, then drag to select 123

7条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-08 20:04

    If you want to catch the changes to the input's value (including the changes made by dragging part of the text for example), you can watch the input event.

    $('input#foo').on("input", function(){
      alert($(this).val());
    });
    
    

提交回复
热议问题