aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/htmlinputelement/labels
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/htmlinputelement/labels')
-rw-r--r--files/zh-cn/web/api/htmlinputelement/labels/index.html71
1 files changed, 71 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/htmlinputelement/labels/index.html b/files/zh-cn/web/api/htmlinputelement/labels/index.html
new file mode 100644
index 0000000000..5015d41a0d
--- /dev/null
+++ b/files/zh-cn/web/api/htmlinputelement/labels/index.html
@@ -0,0 +1,71 @@
+---
+title: HTMLInputElement.labels
+slug: Web/API/HTMLInputElement/labels
+translation_of: Web/API/HTMLInputElement/labels
+---
+<div>{{APIRef("DOM")}}</div>
+
+<p> <code><strong>HTMLInputElement.labels</strong></code> 为只读属性,它返回一个{{domxref("NodeList")}} 实例,绑定当前的{{HTMLElement("input")}} 节点的{{HTMLElement("label")}} 元素。</p>
+
+
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">var <var>labelElements</var> = <var>input</var>.labels;
+</pre>
+
+<h3 id="Return_value">Return value</h3>
+
+<p> {{domxref("NodeList")}} 包含 <code>&lt;label&gt;</code> 元素和 <code>&lt;input&gt;</code> 元素.</p>
+
+<h2 id="实例">实例</h2>
+
+<h3 id="HTML">HTML</h3>
+
+<pre class="brush: html">&lt;label id="label1" for="test"&gt;Label 1&lt;/label&gt;
+&lt;input id="test"/&gt;
+&lt;label id="label2" for="test"&gt;Label 2&lt;/label&gt;
+</pre>
+
+<h3 id="JavaScript">JavaScript</h3>
+
+<pre class="brush: js">window.addEventListener("DOMContentLoaded", function() {
+ const input = document.getElementById("test");
+ for(var i = 0; i &lt; input.labels.length; i++) {
+ console.log(input.labels[i].textContent); // "Label 1" and "Label 2"
+ }
+});</pre>
+
+<p>{{EmbedLiveSample("Example", "100%", 30)}}</p>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName("HTML WHATWG", "forms.html#dom-lfe-labels", "labels")}}</td>
+ <td>{{Spec2("HTML WHATWG")}}</td>
+ <td>No change</td>
+ </tr>
+ <tr>
+ <td>{{SpecName("HTML5 W3C", "forms.html#dom-lfe-labels", "labels")}}</td>
+ <td>{{Spec2("HTML5 W3C")}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容">浏览器兼容</h2>
+
+<div>
+<div class="hidden">本页兼容表是由结构化数据生成的。如果你乐意为数据做贡献,请点击<a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> 给我们发送请求。</div>
+
+<p>{{Compat("api.HTMLInputElement.labels")}}</p>
+</div>