我在文本区域和文本字段上收到 inputmode 属性的验证错误。验证器告诉我此时元素输入不允许属性输入模式但是the HTML5 spec indicates that it is allowed .
这段代码真的有问题,还是验证器出了问题?
这是一个简单的案例,它会产生这种类型的验证错误(两次),一次是在电子邮件输入上,另一次是在文本区域上。
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<form method="post" action="contactme.php">
<label class='pas block'>
Your E-Mail:<br/>
<input type='email' name='email' required inputmode='latin' placeholder='your e-mail here' />
</label>
<label class='pas block'>
Your Message:<br/>
<textarea name='message' required inputmode='latin' placeholder='and your message here!'></textarea>
</label>
</form>
</body>
</html>
最佳答案
此外,请在此处查看有关哪些属性适用于不同输入类型的图表: http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#attr-input-type
“inputmode”属性只适用于“text”和“search”。
更新 2019-09-04:“inputmode”现在是一个全局属性(根据 WHATWG),可以在任何 HTML 元素上指定:https://html.spec.whatwg.org/multipage/dom.html#global-attributes
“inputmode”的另一个引用页面: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode
另一方面,“inputmode”不是 W3C HTML5 属性,而是 W3C HTML 5.1 属性(至少在我写这篇文章时是这样)。更新 2019-09-04:“inputmode”已从 HTML 5.2 和 HTML 5.3 中删除。
关于forms - inputmode 属性是否有效(在 HTML5 表单中)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13269799/