Input type “number” won't resize

后端 未结 7 1549
面向向阳花
面向向阳花 2020-12-13 05:45

Why won\'t my input resize when I change the type to type=\"number\" but it works with type=\"text\"?

EXAMPLE

    Email: &l         


        
7条回答
  •  天涯浪人
    2020-12-13 06:15

    Use an on onkeypress event. Example for a zip code box. It allows a maximum of 5 characters, and checks to make sure input is only numbers.

    Nothing beats a server side validation of course, but this is a nifty way to go.

    function validInput(e) {
      e = (e) ? e : window.event;
      a = document.getElementById('zip-code');
      cPress = (e.which) ? e.which : e.keyCode;
    
      if (cPress > 31 && (cPress < 48 || cPress > 57)) {
        return false;
      } else if (a.value.length >= 5) {
        return false;
      }
    
      return true;
    }
    #zip-code {
      overflow: hidden;
      width: 60px;
    }
    
    

提交回复
热议问题