<input type="checkbox">
HTML input元素 <input type="checkbox">
允许你为表单中(或不在表单中)的提交项选择一个单一值。
注意: 若表单提交时,checkbox未勾选,则提交的值并非为value=unchecked;此时的值不会被提交到服务器。
属性
该元素包含全局属性。
checked
-
当type属性的值为
checkbox时
, 这个属性的存在表示input是否默认被选中。你可以将该属性设置为checked="checked",
或更简单地只设置为checked。
value
- 指定input的值。如果省略,获取该元素的值的结果为字符串"on"。
请注意,如果value值发生改变后页面重新加载,Gecko和IE会忽略HTML源代码中设置的value值。 indeterminate
- 指定checkbox处于不定状态(在大多数平台,这样会产生一个划过checkbox的横线)。
示例
<p>
<input type="checkbox" id="cbox1" value="first_checkbox">
<label for="cbox1">This is the first checkbox</label>
</p>
<p>
<input type="checkbox" id="cbox2" value="second_checkbox" checked="checked">
<label for="cbox2">This is the second checkbox, which is checked</label>
</p>
以上代码将产生2个checkbox,如下所示:
规范
规范 | 状态 | |
HTML Living Standard <checkbox> |
Living Standard | |
HTML5 <checkbox> |
Recommendation | |
HTML 4.01 Specification <checkbox> |
Recommendation |
浏览器兼容性
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help! (en-US)
特性 | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
基本支持 | 1.0 | 1.0 (1.7 or earlier) | 2 or earlier | 1.0 | 1.0 |
type=checkbox | 1.0 | 1.0 (1.7 or earlier) 3.6 (1.9.2) for indeterminate value |
2 | 1.0 | 1.0 |
特性 | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
基本支持 | (Yes) | 4.0 (2.0) | (Yes) | (Yes) | (Yes) |
type=checkbox | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |