inputmode

inputmode 全局属性enumerated 属性,提示用户在编辑元素或其内容时可能输入的数据类型。这允许浏览器显示适当的虚拟键盘。

¥The inputmode global attribute is an enumerated attribute that hints at the type of data that might be entered by the user while editing the element or its contents. This allows a browser to display an appropriate virtual keyboard.

它主要用于 <input> 元素,但可用于 contenteditable 模式下的任何元素。

¥It is used primarily on <input> elements, but is usable on any element in contenteditable mode.

重要的是要了解 inputmode 属性不会导致对输入强制执行任何有效性要求。要要求输入符合特定数据类型,请选择适当的 <input> element type。有关选择 <input> 类型的具体指南,请参阅 部分。

¥It's important to understand that the inputmode attribute doesn't cause any validity requirements to be enforced on input. To require that input conforms to a particular data type, choose an appropriate <input> element type. For specific guidance on choosing <input> types, see the Values section.

¥Values

该属性可以具有以下任意值:

¥The attribute can have any of the following values:

none

没有虚拟键盘。当页面实现自己的键盘输入控件时。

text(默认值)

用户当前区域设置的标准输入键盘。

decimal

小数数字输入键盘,包含用户区域设置的数字和小数点分隔符(通常为 .,)。设备可能会也可能不会显示减号键 (-)。

numeric

数字输入键盘,但只需要数字 0-9。设备可能会也可能不会显示减号键。

tel

调用键盘输入,包括数字 0–9、星号 (*) 和井号 (#) 键。需要调用号码的输入通常应使用 <input type="tel">

针对搜索输入优化的虚拟键盘。例如,返回/提交密钥 可能被标记为 "搜索",以及可能的其他优化。需要搜索查询的输入通常应使用 <input type="search">

email

为输入电子邮件地址而优化的虚拟键盘。通常包括 @ 字符以及其他优化。需要电子邮件地址的输入通常应使用 <input type="email">

url

针对输入 URL 进行优化的键盘。例如,这可能会使 / 键更加突出。增强功能可能包括历史记录访问等。需要 URL 的输入通常应使用 <input type="url">

规范

Specification
HTML Standard
# attr-inputmode

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also