有没有办法有一个屏蔽数字输入字段?

发布于 2024-12-19 03:52:51 字数 275 浏览 3 评论 0原文

我正在 Android 上创建一个 HTML5 应用程序,对于这个特定场景,我们有一个用于信用卡安全代码的输入字段,我们希望强制输入字段仅包含数字并被屏蔽。

我没有运气搜索这个特定的案例,从我自己研究/尝试中可以看出,这不能纯粹通过 HTML5 来完成(因为数字和密码都是类型选项,并且只有一种类型可以被使用)。我是否遗漏了一些东西,有一种方法可以在通过 HTML5 屏蔽输入的同时弹出数字键盘,或者是否有另一种方法可以强制键盘输入类型或通过 CSS 或 JavaScript 屏蔽输入?

感谢您的帮助!

I am creating an HTML5 application on an Android and for this specific scenario, we have an input field that is for a credit card's security code and we want to force the input field to be numberic only and masked.

I have had no luck searching for this specific case and from everything I can tell from researching/trying it out for myself is that this can't be done purely through HTML5 (since number and password are both options for type and only one type can be used). Am I missing something and there is a way to pop-up the numeric keyboard while having the input be masked through HTML5 or is there another way to force the keyboard input type or masking the input through CSS or JavaScript?

Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

轻拂→两袖风尘 2024-12-26 03:52:51

如果只需要在基于WebKit的浏览器中工作,并且“纯粹通过HTML5”允许使用CSS,您可以尝试:

input[type=number] {
    -webkit-text-security: disc;
}

我不确定目前其他浏览器是否有等效的,将来这可能是可控的通过 外观 CSS 属性。 CSS3 版本的 appearance 已从规范中删除,因此看来您必须等待 text-security 的标准化才能获得跨浏览器解决方案。

If it's only required to work in WebKit based browsers, and CSS is allowed in 'purely through HTML5', you could try:

input[type=number] {
    -webkit-text-security: disc;
}

I'm not sure if there's currently any equivalent for other browsers, in the future this may be controllable through the appearance CSS property. The CSS3 version of appearance has been dropped from the spec, so it looks like you'll have to wait for the standardization of text-security for a cross browser solution.

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