【问题标题】:Is the inputmode attribute valid (in HTML5 forms) or not?inputmode 属性是否有效(以 HTML5 形式)?
【发布时间】:2012-10-27 12:19:43
【问题描述】:

我收到文本区域和文本字段上的 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>

【问题讨论】:

  • 可能验证器不是 HTML5 验证器或处于 HTML5 模式
  • 我尝试了 w3c 验证器和 whatwg 验证器。两个验证器都处于 html5 模式,并且(即因为)此示例具有 html5 doctype
  • 也许inputmode 不能与type 的(某些值)组合?
  • 有效是的,但是应该注意的是,目前没有浏览器(据我所知已经实现它)twitter.com/scunliffe/status/691370670018686976 - 这是令人沮丧的,因为它会用@克服其他(恕我直言的错误) 987654327@
  • 与有效性/规范的问题无关,但您可以在caniuse.com/#feat=input-inputmode 看到对该功能的实际支持。到今天,令人沮丧的是,它仍然完全没有在任何地方实现。

标签: forms html validation


【解决方案1】:

此外,请参阅图表,了解哪些属性适用于不同的输入类型: 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

“输入模式”的另一个参考页面: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode

另一方面,“inputmode”不是 W3C HTML5 属性,而是 W3C HTML 5.1 属性(至少在我写这篇文章的时候)。 2019 年 9 月 4 日更新:“输入模式”已从 HTML 5.2 和 HTML 5.3 中删除。

【讨论】:

  • 谢谢 - 该图表非常方便(至少对我而言)哪些选项/属性适用于哪些输入类型。
  • 截至 2019 年,inputmode 似乎不再是您链接的规范的一部分。
  • @balu - 看起来他们从图表中删除了它......而且,它现在是一个全局属性:html.spec.whatwg.org/multipage/dom.html#global-attributes
【解决方案2】:

HTML5 规范说

以下内容属性不得指定且不适用于元素:accept、alt、checked、dirname、formaction、formenctype、formmethod、formnovalidate、formtarget、height、inputmode、max、 min、src、步长和宽度。

https://html.spec.whatwg.org/multipage/input.html#e-mail-state-(type=email)的簿记详细信息中

【讨论】:

  • 这个记账细节专门针对[type=email]元素,对于文本和搜索状态(spec)它说以下常见的输入元素内容属性、IDL属性和方法适用于元素:..... 输入模式
【解决方案3】:

问题提出五年后,有些人可能想知道为什么@dsas 列出的某些属性不会触发此类错误,例如enctype 答案是简单的支持,而 enctype 例如获得了广泛的支持 inputmethod 仅支持 IE11 和 Edge 14,更多信息请点击 here

【讨论】:

    猜你喜欢
    • 2012-04-01
    • 2012-10-18
    • 2021-12-21
    • 2023-04-01
    • 2010-12-04
    • 2012-01-05
    • 1970-01-01
    相关资源
    最近更新 更多