HTML DOM教程 22-HTML DOM Form 对象
HTML DOM教程 22-HTML DOM Form 對象
?
1:Form 對象
Form 對象代表一個 HTML 表單。
在 HTML 文檔中 <form> 每出現一次,Form 對象就會被創建。
2:Form 對象的集合
| elements[] | 包含表單中所有元素的數組。 | 5 | 1 | 9 | Yes |
3:Form 對象的屬性
| 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
| 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 |
5:Form 對象的方法
| reset() | 把表單的所有輸入元素重置為它們的默認值。 | 5 | 1 | 9 | Yes |
| submit() | 提交表單。 | 5 | 1 | 9 | Yes |
6:Form 對象的事件句柄
| onreset | 在重置表單元素之前調用。 | 5 | 1 | 9 | Yes |
| onsubmit | 在提交表單之前調用。 | 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" οnclick="formSubmit()" value="Submit">
</form>
</body>
</html>
8:reset() 方法
調用該方法的結果類似用戶單擊了 Reset 按鈕的結果,只是表單的事件句柄 onreset 不會被調用。
<html>
<head>
<script type="text/javascript">
function formReset()
{
document.getElementById("myForm").reset()
}
</script>
</head>
<body>
<form id="myForm">
Name: <input type="text" size="20"><br />Age: <input type="text" size="20"><br />
<br />
<input type="button" οnclick="formReset()" value="Reset">
</form>
</body>
</html>
轉載于:https://www.cnblogs.com/pricks/archive/2009/05/04/1449106.html
總結
以上是生活随笔為你收集整理的HTML DOM教程 22-HTML DOM Form 对象的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HTML DOM教程 21-HTML D
- 下一篇: 全屏的三栏div+css布局示例