开发者

Only allow textbox values from 1 to 11 using JavaScript

开发者 https://www.devze.com 2023-03-10 05:22 出处:网络
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

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消