aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/document/forms/index.html
blob: 12b223e90564a3781bb64004e2cdd2949fa78006 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---
title: Document.forms
slug: Web/API/Document/forms
tags:
  - Document.forms
translation_of: Web/API/Document/forms
---
<p>{{APIRef("DOM")}}</p>

<p><code><strong>forms</strong> </code>返回当前文档中的 {{HTMLElement("form")}}元素的一个集合(一个 {{domxref("HTMLCollection")}})。</p>

<h2 id="Syntax" name="Syntax">语法</h2>

<pre class="eval"><code>let collection</code> = document.forms;
</pre>

<h2 id="Example" name="Example">例子: 获取表单信息</h2>

<pre class="brush: html">&lt;html&gt;

&lt;head&gt;
&lt;title&gt; document.forms example&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form id="robby"&gt;
 &lt;input type="button" onclick="alert(document.forms[0].id);"
 value="robby's form" /&gt;
&lt;/form&gt;

&lt;form id="dave"&gt;
 &lt;input type="button" onclick="alert(document.forms[1].id);"
 value="dave's form" /&gt;
&lt;/form&gt;

&lt;form id="paul"&gt;
 &lt;input type="button" onclick="alert(document.forms[2].id);"
 value="paul's form" /&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>

<h2 id="例子_获取表单内的元素"> 例子: 获取表单内的元素</h2>

<pre class="brush: js">var selectForm = document.forms[index];
var selectFormElement = document.forms[index].elements[index];
</pre>

<h2 id="Specification" name="Specification">规范</h2>

<p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-1689064">forms DOM Level 2 HTML: forms</a></p>

<h2 id="See_Also" name="See_Also">相关链接</h2>

<ul>
 <li><a href="/zh-cn/DOM/HTMLFormElement" title="zh-cn/DOM/form">DOM:form</a></li>
</ul>

<p>{{ languages( { "ja": "ja/DOM/document.forms", "pl": "pl/DOM/document.forms" , "en": "en/DOM/document.forms" } ) }}</p>