diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/html/element/input/checkbox/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/html/element/input/checkbox/index.html')
-rw-r--r-- | files/zh-cn/web/html/element/input/checkbox/index.html | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/files/zh-cn/web/html/element/input/checkbox/index.html b/files/zh-cn/web/html/element/input/checkbox/index.html new file mode 100644 index 0000000000..14a0d21aef --- /dev/null +++ b/files/zh-cn/web/html/element/input/checkbox/index.html @@ -0,0 +1,137 @@ +--- +title: <input type="checkbox"> +slug: Web/HTML/Element/Input/checkbox +translation_of: Web/HTML/Element/input/checkbox +--- +<p><span class="seoSummary">HTML input元素 <strong><code><input type="checkbox"></code></strong> 允许你为表单中(或不在表单中)的提交项选择一个单一值。</span></p> + +<div class="note"> +<p><strong>注意</strong>: 若表单提交时,checkbox未勾选,则提交的值并非为value=unchecked;此时的值不会被提交到服务器。</p> +</div> + +<h2 id="属性">属性</h2> + +<p>该元素包含<a href="https://developer.mozilla.org/zh-CN/docs/Web/HTML/Global_attributes">全局属性</a>。</p> + +<dl> + <dt>{{htmlattrdef("checked")}}</dt> + <dd> + <p>当<strong>type</strong>属性的值为<code>checkbox时</code>, 这个属性的存在表示input是否默认被选中。你可以将该属性设置为<code>checked="checked",</code>或更简单地只设置为<code>checked。</code></p> + </dd> + <dt>{{htmlattrdef("value")}}</dt> + <dd>指定input的值。如果省略,获取该元素的值的结果为字符串"on"。<br> + 请注意,如果value值发生改变后页面重新加载,Gecko和IE<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=46845#c186">会忽略HTML源代码中设置的value值</a>。</dd> + <dt>{{htmlattrdef("indeterminate")}}</dt> + <dd>指定checkbox处于不定状态(在大多数平台,这样会产生一个划过checkbox的横线)。</dd> +</dl> + +<h2 id="示例">示例</h2> + +<pre class="brush: html"><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> +</pre> + +<p>以上代码将产生2个checkbox,如下所示:</p> + +<p>{{EmbedLiveSample("Example")}}</p> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <td>规范</td> + <td>状态</td> + </tr> + <tr> + </tr> + <tr> + <td>{{SpecName('HTML WHATWG', 'forms.html#checkbox-state-(type=checkbox)', '<checkbox>')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('HTML5 W3C', 'forms.html#checkbox-state-(type=checkbox)', '<checkbox>')}}</td> + <td>{{Spec2('HTML5 W3C')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('HTML4.01', 'interact/forms.html#checkbox', '<checkbox>')}}</td> + <td>{{Spec2('HTML4.01')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>特性</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>基本支持</td> + <td>1.0</td> + <td>{{CompatGeckoDesktop("1.7 or earlier")}}</td> + <td>2 or earlier</td> + <td>1.0</td> + <td>1.0</td> + </tr> + <tr> + <td>type=checkbox</td> + <td>1.0</td> + <td>{{CompatGeckoDesktop("1.7 or earlier")}}<br> + {{CompatGeckoDesktop("1.9.2")}} for <code>indeterminate</code> value</td> + <td>2</td> + <td>1.0</td> + <td>1.0</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>特性</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>基本支持</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile("2.0")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + <tr> + <td>type=checkbox</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> |