How can I limit possible inputs in a HTML5 “number” element?

前端 未结 26 2825
感动是毒
感动是毒 2020-11-22 05:12

For element, maxlength is not working. How can I restrict the maxlength for that number element?

26条回答
  •  一个人的身影
    2020-11-22 05:13

    Lets say you wanted the maximum allowed value to be 1000 - either typed or with the spinner.

    You restrict the spinner values using: type="number" min="0" max="1000"

    and restrict what is typed by the keyboard with javascript: onkeyup="if(parseInt(this.value)>1000){ this.value =1000; return false; }"

    
    

提交回复
热议问题