วัตถุแบบฟอร์ม HTML DOM
แบบฟอร์มวัตถุ
วัตถุแบบฟอร์มแสดงถึงองค์ประกอบ HTML <form>
เข้าถึงวัตถุแบบฟอร์ม
คุณสามารถเข้าถึงองค์ประกอบ <form> โดยใช้ getElementById():
ตัวอย่าง
var x = document.getElementById("myForm");
เคล็ดลับ:คุณยังสามารถเข้าถึงองค์ประกอบ <form> โดยใช้คอลเลกชันแบบฟอร์ม
สร้างวัตถุแบบฟอร์ม
คุณสามารถสร้าง <form> องค์ประกอบโดยใช้ document.createElement() วิธีการ:
ตัวอย่าง
var x = document.createElement("FORM");
ฟอร์มออบเจ็กต์คอลเล็กชัน
Collection | Description |
---|---|
elements | Returns a collection of all elements in a form |
คุณสมบัติของวัตถุแบบฟอร์ม
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 |
แบบฟอร์ม Object Methods
Method | Description |
---|---|
reset() | Resets a form |
submit() | Submits a form |
คุณสมบัติและเหตุการณ์มาตรฐาน
ออบเจ็กต์ Form ยังสนับสนุนคุณสมบัติและเหตุการณ์ มาตรฐาน อีกด้วย
หน้าที่เกี่ยวข้อง
กวดวิชา HTML: แบบฟอร์ม HTML
บทช่วยสอน JavaScript: JS Forms/Validation
การอ้างอิง HTML: แท็ก HTML <form>