aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/htmlformelement/elements/index.html
blob: ebb26003b0c868589de283f0ab7c9e914e0d5b84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
---
title: HTMLFormElement.elements
slug: Web/API/HTMLFormElement/elements
translation_of: Web/API/HTMLFormElement/elements
---
<div>
 <span style="font-size: 30px; font-weight: 700; letter-spacing: -1px; line-height: 30px;">小结</span></div>
<p><strong>elements</strong> 返回一个 {{domxref("HTMLFormControlsCollection")}} ({{ HTMLVersionInline(4) }} <code><a class="external" href="http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-75708506">HTMLCollection</a></code>) 其中包含FORM的所有控件。需要注意的是,其中不包括<code><code style="font-size: 14px;">type等于</code></code><span style="font-family: 'Courier New', 'Andale Mono', monospace; line-height: normal;">image的</span><code style="font-size: 14px;"><a href="/en-US/docs/HTML/Element/Input" title="input">input</a></code><span style="line-height: 1.5;"> 元素。</span></p>
<p>你可以通过 <a href="/en-US/docs/DOM/element.name" title="DOM/element.name">name</a> 或 <a href="/en-US/docs/DOM/element.id" title="DOM/element.id">id</a>来访问对应的控件。</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><em>nodeList</em> = <em>HTMLFormElement</em>.elements
</pre>
<h2 id="Example" name="Example">实例</h2>
<pre class="brush:js">var inputs = document.getElementById("form1").elements;
var inputByIndex = inputs[2];
var inputByName = inputs["login"];
</pre>
<h2 id="Specification" name="Specification">规范</h2>
<ul>
 <li><a class="external" href="http://www.w3.org/TR/html5/forms.html#dom-form-elements" title="http://www.w3.org/TR/html5/forms.html#dom-form-elements">HTML5, Section 4.10.3, The form Element</a></li>
 <li><a class="external" href="http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-76728479">DOM Level 2 HTML: elements</a></li>
</ul>