号码输入字段,禁止用户手动输入号码
我有一个数字输入字段,用于设置事件的到期时间。即用户可以创建一个在 X 天后过期的事件; x 是使用输入字段中的数字来选择的。
我已将数字输入字段设置为最小值为 1,最大值为 7,但用户仍然可以手动输入他们想要的任何数字(即 0 或 > 8)。
我正在尝试找出一种方法来禁止用户手动在字段中输入数字,而不必使用 JQuery 等进行任何操作。
有谁知道这是否可能?
我正在开发的应用程序是在 Rails 中,但我认为这更多是一个 HTML/Javascript 问题。
预先非常感谢。
I have a number input field for setting the expiry of an event. i.e. a user can create an event that expires in X days; the x is chosen using a number in put field.
I have set the number input field to have a min value of 1 and max of 7, but a user can still manually type in whatever number they want (i.e. 0 or >8).
I am trying to figure out a way to disable the user from manually entering numbers into the field without having to do anything with JQuery, etc.
Does anyone know if this is possible?
The app I'm working on is in Rails, but I think this is more an HTML/Javascript question.
Thanks a lot in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将阻止某人手动输入数字:
示例: http://jsfiddle.net/ CWadc/10
This will prevent someone from manually entering a number:
Example: http://jsfiddle.net/CWadc/10
您可以像这样限制有效数字(对于 jQuery 1.7.x);
jsFiddle 示例
You can limit valid numbers like this (for jQuery 1.7.x);
jsFiddle example