List元素HTML的Checked属性

我正在阅读有关HTML5的内容,并遇到了这个简单的示例。我不明白li标记如何在不出现浏览器错误的情况下获取选中的属性?

唯一具有选中属性的元素是单选按钮或选择元素。

在哪里可以找到特定元素可以采用的属性?

<ul id="group1" class="radiogroup">
  <li tabindex="0" class="radio" checked>
    Water
  </li>
  <li tabindex="-1" class="radio">
    Tea
  </li>
  <li tabindex="-1" class="radio">
    Coffee
  </li>
  <li tabindex="-1" class="radio">
    Cola
  </li>
  <li tabindex="-1" class="radio">
    Ginger Ale
  </li>
</ul>
评论
  • 笑回首
    笑回首 回复

    Browsers are required to do the best they can with whatever markup is given to them. That means handling this invalid attribute. Yes, it is invalid and not allowed on <li> tags.

  • Dulle
    Dulle 回复

    You can find that type of information on MDN Web Docs. For example, after looking that the documentation for the HTML Element <li> Tag

    TLDR;

    The <li> tag has its own attributes as well as inherits the global attributes (i.e style, class, id, etc..) that is special to it which is the value attribute.

    <li> attributes:

    • 类型

    Global Attributes can be found here