布尔属性的语法是什么,例如选中的复选框,在 HTML 中? [英] What is the syntax for boolean attributes, e.g. a checked checkbox, in HTML?
问题描述
听起来有点愚蠢的问题,但我想知道在 HTML 中选中/取消选中复选框的最佳方式是什么.
Sounds like a bit of a silly question, but I am wondering what is the best way of stating that a checkbox is checked/unchecked in HTML.
我见过很多不同的例子:
I have seen many different examples:
<input type="checkbox" checked="checked" />
<input type="checkbox" />
<input type="checkbox" checked="yes" />
<input type="checkbox" checked="no" />
<input type="checkbox" checked="true" />
<input type="checkbox" checked="false" />
哪些浏览器可以使用其中的哪些浏览器,最重要的是,jQuery 是否确定在所有 3 个中选中了哪个框?
Which browsers work with which ones of these, and most importantly, does jQuery figure out which box is checked in all 3?
W3C 规范似乎暗示只有检查过的属性是正确的.这是否意味着 checked="false" 和 checked="no" 仍会选中该框?
The W3C spec seems to imply that just the checked attr being there is correct. Does that mean that checked="false" and checked="no" will still check the box though?
推荐答案
在 HTML 中:
<input type="checkbox" checked>
<input type="checkbox" checked="checked">
对于 XHTML,您必须使用属性/值匹配对:
For XHTML you have to use attribute/value matching pairs:
<input type="checkbox" checked="checked" />
这篇关于布尔属性的语法是什么,例如选中的复选框,在 HTML 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!