为什么输入元素的inputmode属性不像MDN文档所描述的那样使用虚拟键盘?

问题描述 投票:1回答:3

inputmode属性在this document on the Mozilla Developer Network (MDN)中描述的任何流行浏览器中都没有效果,因为它没有虚拟键盘。

我在这里重现代码片段:

<html>
    <label for = "txtName">Name</label>&nbsp;<input name = "txtName" type = "text" inputmode = "text" /><br />
    <label for = "txtAge">Age</label>&nbsp;<input name = "txtAge" type = "text" inputmode = "numeric" /><br />
    <label for = "txtEmail">Email</label>&nbsp;<input name = "txtEmail" type = "text" inputmode = "email" /><br />
    <label for = "txtUrl">Url</label>&nbsp;<input name = "txtUrl" type = "text" inputmode = "url" /><br />
    <label for = "txtPhoneNumber">Phone Number</label>&nbsp;<input name = "txtPhoneNumber" type = "text" inputmode = "tel" /><br />
</html>

我错过了什么吗?

html html5
3个回答
1
投票

根据caniuse.com的说法,任何主流浏览器都默认不支持此功能。所以今天它不会有任何影响。看起来支持即将到来 - Firefox有一个启用它的标志,Chrome将其标记为“正在开发中”,而Edge表示它正在“正在考虑中”。


0
投票

此属性仅与具有动态键盘的设备上的浏览器相关。

“inputmode”只是提示浏览器显示哪个虚拟键盘,它不启用虚拟键盘。在触摸屏手机和笔记本电脑上,它应该工作并显示正确的键盘(在大多数设备上,并非所有设备都保证)。 而对于其他PC,你可以尝试一些虚拟键盘扩展,如Google Input Tools,但再次它不能保证工作。 也用于电话,电子邮件和网址

<input type="tel">
<input type="email">
<input type="url">

在各种设备和浏览器上提供更好的支持。


0
投票

我相信这仅用于手机,以选择要显示的键盘类型。

正如this文章所述:inputmode属性告诉浏览器在具有动态键盘的设备上显示哪个键盘。 inputmode属性适用于文本,搜索和密码输入类型以及。此属性仅与具有动态键盘的设备上的浏览器相关。

© www.soinside.com 2019 - 2024. All rights reserved.