【问题标题】:HTML5 radiobuttons, checkbox and select option tags: checked='checked' and selected='selected', or just checked and selectedHTML5 单选按钮、复选框和选择选项标签:checked='checked' 和 selected='selected',或者只是选中并选中
【发布时间】:2016-04-15 09:38:15
【问题描述】:

假设 HTML5,指示复选框、单选按钮或选择选项被选中或选中的正确方式是什么?

是不是这样,看起来很常用,但对我来说似乎是多余的:

<input type='checkbox' checked='checked'> I'm checked

<input type='radio' checked='checked'> I'm also checked

<select>
  <option>First</option>
  <option selected='selected'>I'm selected</option>
</select>

或者像这样,这似乎更有意义并且似乎也有效:

<input type='checkbox' checked> I'm checked

<input type='radio' checked> I'm also checked

<select>
  <option>First</option>
  <option selected>I'm selected</option>
</select>

后者是否存在兼容性问题?

【问题讨论】:

    标签: html tags attributes selected checked


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      这两种方式似乎都通过了W3 HTML5 validator,所以它们都应该是正确的。 我更喜欢第二种方法,因为它使用更少的代码并且对我来说更容易,但这完全是个人的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-01
        • 2019-12-12
        • 2013-07-24
        • 1970-01-01
        • 2012-09-28
        • 2013-06-23
        相关资源
        最近更新 更多