HTML 角色=“形式”

示例

具有地标性的区域,包含总体上组合在一起构成表单的项目和对象的集合。

使用在语义上正确的HTML元素<form>暗含默认的ARIA语义,这role=form是不需要的,因为您不应该将对比角色应用于已经是语义的元素,因为添加角色会覆盖元素的本机语义。

不需要设置与默认隐式ARIA语义相匹配的ARIA角色和/或aria- *属性,并且不建议您这样做,因为浏览器已经设置了这些属性。

<form action="">
  <fieldset>
    <legend>Login form</legend>
    <div>
      <label for="username">Your username</label>
      <input type="text" id="username" aria-describedby="username-tip" required />
      <div role="tooltip" id="username-tip">Your username is your email address</div>
    </div>
    <div>
      <label for="password">Your password</label>
      <input type="text" id="password" aria-describedby="password-tip" required />
      <div role="tooltip" id="password-tip">Was emailed to you when you signed up</div>
    </div>
  </fieldset>
</form>

您将role=form在非语义元素上使用(不建议使用,无效)

<div role=form>
  <input type="email" placeholder="Your email address">
  <button>Sign up</button>
</div>