在移动网络表单中强制执行数字

发布于 2024-08-20 17:53:15 字数 151 浏览 9 评论 0原文

我有一个针对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

掩饰不了的爱 2024-08-27 17:53:15

您应该能够使用“数字”输入类型,它是 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...

£冰雨忧蓝° 2024-08-27 17:53:15

在 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.

彡翼 2024-08-27 17:53:15
<input type='tel' /> 

将在 Android、WP8 和 iPhone 默认浏览器以及 Android 版 Chrome 上显示数字键盘。在我的 Android 浏览器上,非数字字符在模糊时被剥离。

<input type='number' /> 

应该适用于浮动。在我的两个 Android 浏览器上,它还会自动删除模糊前导零。

<input type='tel' /> 

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.

<input type='number' /> 

should work fine for floats. On both of my Android browsers, it also automatically removes leading zeros onblur.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文