inputmode
属性为触摸屏设备上的浏览器提供了一个有价值的提示,从而指导它们选择适当的屏幕键盘<input>
和<textarea></textarea>
elements. Unlike altering the input type, inputmode
solely dictates keyboard display, not input interpretation.
While possessing a lengthy history, widespread adoption by major mobile browsers (Safari and Chrome) is relatively recent. Prior implementations in Firefox for Android were short-lived. This support, detailed on caniuse.com, shows version-specific compatibility. Note that my testing suggests Opera Mini and Opera Mobile support contradicts caniuse data.
Although the WHATWG specification documents inputmode
, the W3C 5.2 spec omits it, hinting at potential obsolescence. However, given WHATWG documentation and browser support, we'll consider the WHATWG standard.
inputmode
accepts several values:
none
This value prevents keyboard display in Chrome for Android, though iOS 12.2 shows its default keyboard. It's intended for inputs with custom keyboard controls.
numeric
Highly useful for numerical inputs (PINs, zip codes, etc.). Unlike type="number"
, it allows maxlength
, minlength
, and pattern
attributes, enhancing versatility. While often used with type="tel"
, this is semantically incorrect. The pattern="\d*"
attribute provides a similar effect but limits input strictly to numbers; Android doesn't allow switching to an alphanumeric keyboard, potentially blocking valid entries.
tel
Optimizes telephone number input. It provides a standard telephone keypad (0-9, #, *) with alphabetic mnemonics (ABC, DEF, etc.).
decimal
Produces a keyboard similar to tel
on iOS, replacing the * # key with a decimal point. Android uses the standard numeric keyboard.
email
Includes the @
and .
characters, improving email address entry. iOS's email suggestions might cause confusion. Useful for custom email validation.
url
Facilitates URL entry by including common web address characters (.
, /
) and locale-specific TLDs. Use type="url"
for input validation.
search
Displays a "Go" (iOS) or "Enter" (Android) key, ideal for search forms. type="search"
offers alternative visual cues.
Additional Notes
- Chromium-based Android browsers (Edge, Brave, Opera) mirror Chrome's
inputmode
behavior. - iPad and Android tablet behavior largely mirrors iPhone and Android phones, respectively, excluding third-party keyboards.
-
kana
,katakana
, andlatin-name
values from earlier specifications are no longer implemented. Interestingly,latin-name
on iOS suggests the user's name.
Demo
A live demo showcasing these inputmode
variations is available (link to be provided if a demo is created).
References
- WHATWG specification
- MDN documentation
- caniuse.com
- Chrome Platform Status (Chromium Ticket #244688)
以上是您想知道的有关输入模式的一切的详细内容。更多信息请关注PHP中文网其他相关文章!

SVG具有自己的一套元素,属性和属性集,以至于内联SVG代码可能会变得漫长而复杂。通过利用CSS和SVG 2规范的一些即将到来的功能,我们可以减少该代码以进行清洁标记。

PWA(Progressive Web应用程序)已经与我们在一起了一段时间。但是,每次我尝试向客户解释它时,同样的问题都会出现:“我的用户会成为


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

Dreamweaver Mac版
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

WebStorm Mac版
好用的JavaScript开发工具