HTML DOM教程 22-HTML DOM Form 对象
1:Form 对象
Form 对象代表一个 HTML 表单。
在 HTML 文档中 <form> 每出现一次,Form 对象就会被创建。
2:Form 对象的集合
集合 | 描述 | IE | F | O | W3C |
---|---|---|---|---|---|
elements[] | 包含表单中所有元素的数组。 | 5 | 1 | 9 | Yes |
3:Form 对象的属性
属性 | 描述 | IE | F | O | W3C |
---|---|---|---|---|---|
acceptCharset | 服务器可接受的字符集。 | No | No | No | Yes |
action | 设置或返回表单的 action 属性。 | 5 | 1 | 9 | Yes |
enctype | 设置或返回表单用来编码内容的 MIME 类型。 | 6 | 1 | 9 | Yes |
id | 设置或返回表单的 id。 | 5 | 1 | 9 | Yes |
length | 返回表单中的元素数目。 | 5 | 1 | 9 | Yes |
method | 设置或返回将数据发送到服务器的 HTTP 方法。 | 5 | 1 | 9 | Yes |
name | 设置或返回表单的名称。 | 5 | 1 | 9 | Yes |
target | 设置或返回表单提交结果的 Frame 或 Window 名。 | 5 | 1 | 9 | Yes |
4:Standard Properties
属性 | 描述 | IE | F | O | W3C |
---|---|---|---|---|---|
className | Sets or returns the class attribute of an element | 5 | 1 | 9 | Yes |
dir | Sets or returns the direction of text | 5 | 1 | 9 | Yes |
lang | Sets or returns the language code for an element | 5 | 1 | 9 | Yes |
title | Sets or returns an element's advisory title | 5 | 1 | 9 | Yes |
7:submit() 方法
该方法提交表单的方式与用户单击 Submit 按钮一样,但是表单的 onsubmit 事件句柄不会被调用。
<html>
<head>
<script type="text/javascript">
function formSubmit(){
document.getElementById("myForm").submit()
}
</script>
</head>
<body>
<form id="myForm" action="js_form_action.asp" method="get">
Firstname: <input type="text" name="firstname" size="20"><br />
Lastname: <input type="text" name="lastname" size="20"><br /> <br />
<input type="button" onclick="formSubmit()" value="Submit">
</form>
</body>
</html>
8:reset() 方法
调用该方法的结果类似用户单击了 Reset 按钮的结果,只是表单的事件句柄 onreset 不会被调用。
<html>
<head>
<script type="text/javascript"></head>
function formReset()</script>
{
document.getElementById("myForm").reset()
}
<body>
</body><form id="myForm">
Name: <input type="text" size="20"><br /></form>
Age: <input type="text" size="20"><br />
<br />
<input type="button" onclick="formReset()" value="Reset">
</html>