在移动网络表单中强制执行数字
我有一个针对 Opera Mini 和 Opera Mobile 的简单网络表单。我只使用 HTML 输入元素。
现在我想限制元素仅包含整数。有没有办法在此浏览器中强制执行此操作(即使手机在输入表单时可能会打开数字模式)?
如果我想允许浮动,那么有可能吗?
I have a simple webform targeted for Opera Mini and Opera Mobile. I'm using just a HTML input element.
Now I would like to restrict the element to only have integer numbers. Is there a way to enforce this in this browser (possible even that the phone will have it's number mode on when entering the form)?
And if I wanted to allow floats, is something possible then?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该能够使用“数字”输入类型,它是 HTML5 规范的一部分。我不确定 Opera 是否会自动显示数字键盘,但 iphone 至少会...
You should be able to use the "number" input type, it's part of the HTML5 spec. I'm unsure if Opera will automatically display the numeric keypad but the iphone at least does...
在 XHTML Basic 中,您可以在
标记上使用
inputmode="digits"
来完成此操作。它应该比 HTML5 机制在移动浏览器上得到更广泛的支持。In XHTML Basic, you can use
inputmode="digits"
on your<input>
tags to accomplish this. It ought to be more widely supported on mobile browsers that HTML5 mechanisms.将在 Android、WP8 和 iPhone 默认浏览器以及 Android 版 Chrome 上显示数字键盘。在我的 Android 浏览器上,非数字字符在模糊时被剥离。
应该适用于浮动。在我的两个 Android 浏览器上,它还会自动删除模糊前导零。
will bring up a numeric keypad on Android, WP8, and iPhone default browsers as well as Chrome for Android. On my Android browsers, non-numeric characters are stripped onblur.
should work fine for floats. On both of my Android browsers, it also automatically removes leading zeros onblur.