Đối tượng biểu mẫu DOM HTML
Đối tượng biểu mẫu
Đối tượng Biểu mẫu đại diện cho một phần tử HTML <form>.
Truy cập một đối tượng biểu mẫu
Bạn có thể truy cập phần tử <form> bằng cách sử dụng getElementById ():
Thí dụ
var x = document.getElementById("myForm");
Mẹo: Bạn cũng có thể truy cập phần tử <form> bằng cách sử dụng bộ sưu tập biểu mẫu .
Tạo một đối tượng biểu mẫu
Bạn có thể tạo một phần tử <form> bằng cách sử dụng phương thức document.createElement ():
Thí dụ
var x = document.createElement("FORM");
Bộ sưu tập đối tượng biểu mẫu
Collection | Description |
---|---|
elements | Returns a collection of all elements in a form |
Thuộc tính đối tượng biểu mẫu
Property | Description |
---|---|
acceptCharset | Sets or returns the value of the accept-charset attribute in a form |
action | Sets or returns the value of the action attribute in a form |
autocomplete | Sets or returns the value of the autocomplete attribute in a form |
encoding | Alias of enctype |
enctype | Sets or returns the value of the enctype attribute in a form |
length | Returns the number of elements in a form |
method | Sets or returns the value of the method attribute in a form |
name | Sets or returns the value of the name attribute in a form |
noValidate | Sets or returns whether the form-data should be validated or not, on submission |
target | Sets or returns the value of the target attribute in a form |
Phương thức đối tượng biểu mẫu
Method | Description |
---|---|
reset() | Resets a form |
submit() | Submits a form |
Thuộc tính và sự kiện tiêu chuẩn
Đối tượng Form cũng hỗ trợ các thuộc tính và sự kiện tiêu chuẩn .
Các trang liên quan
Hướng dẫn HTML: Biểu mẫu HTML
Hướng dẫn JavaScript: JS Forms / Validation
Tham chiếu HTML: thẻ <form> HTML