Only allow textbox values from 1 to 11 using JavaScript
I plan for using this with 'number of month'.
I would like to have one textbox where the user开发者_运维知识库 can only enter a number between 1 to 11.
Honestly, a dropdown (<select>
) is far better suited for picking months. It works without JavaScript, provides better accessibility, and will be less error-prone for nerds ("dangit, why isn't this zero-based‽") and normal users alike ("Why do I always forget that July is 7, not 6?").
You may want to consider using a select
element instead of a text box to limit the options.
A newer and nice (IMO) alternative is using HTML5: <input type="number" min="1" max="11" />
You might want to use a Range Slider control for something like this.
Here is a jquery example
http://jqueryui.com/demos/slider/
精彩评论