File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7272- elements/ : 附录:网页元素接口
7373- elements/a.md : <a>
7474- elements/image.md : <img>
75+ - elements/form.md : <form>
7576- elements/input.md : <input>
7677- elements/button.md : <button>
Original file line number Diff line number Diff line change @@ -102,6 +102,16 @@ var selectForm = document.forms[0];
102102
103103上面代码获取文档第一个表单。
104104
105+ 除了使用位置序号,` id ` 属性和` name ` 属性也可以用来引用表单。
106+
107+ ``` javascript
108+ /* HTML 代码如下
109+ <form name="foo" id="bar"></form>
110+ */
111+ document .forms [0 ] === document .forms .foo // true
112+ document .forms .bar === document .forms .foo // true
113+ ```
114+
105115** (3)document.images**
106116
107117` document.images ` 属性返回页面所有` <img> ` 图片节点。
Original file line number Diff line number Diff line change 1+ # <form > 元素
2+
3+ ` <form> ` 元素代表了表单,继承了 HTMLFormElement 接口。
4+
5+ ## HTMLFormElement 的实例属性
6+
7+ - ` elements ` :返回一个类似数组的对象,成员是属于该表单的所有控件元素。该属性只读。
8+ - ` length ` :返回一个整数,表示属于该表单的控件数量。该属性只读。
9+ - ` name ` :字符串,表示该表单的名称。
10+ - ` method ` :字符串,表示提交给服务器时所使用的 HTTP 方法。
11+ - ` target ` :字符串,表示表单提交后,服务器返回的数据的展示位置。
12+ - ` action ` :字符串,表示表单提交数据的 URL。
13+ - ` enctype ` (或` encoding ` ):字符串,表示表单提交数据的编码方法,可能的值有` application/x-www-form-urlencoded ` 、` multipart/form-data ` 和` text/plain ` 。
14+ - ` acceptCharset ` :字符串,表示服务器所能接受的字符编码,多个编码格式之间或空格分隔。
15+ - ` autocomplete ` :字符串` on ` 或` off ` ,表示浏览器是否要对` <input> ` 控件提供自动补全。
16+ - ` noValidate ` :布尔值,表示是否关闭表单的自动校验。
17+
18+ ## HTMLFormElement 的实例方法
19+
20+ - ` submit() ` :提交表单,但是不会触发` submit ` 事件和表单的自动校验。
21+ - ` reset() ` :重置表单控件的值为默认值。
22+ - ` checkValidity() ` :如果控件能够通过自动校验,返回` true ` ,否则返回` false ` ,同时触发` invalid ` 事件。
23+
24+ 下面是一个创建表单并提交的例子。
25+
26+ ``` javascript
27+ var f = document .createElement (' form' );
28+ document .body .appendChild (f);
29+ f .action = ' /cgi-bin/some.cgi' ;
30+ f .method = ' POST' ;
31+ f .submit ();
32+ ```
33+
You can’t perform that action at this time.
0 commit comments