อ็อบเจ็กต์ตัวเลือก HTML DOM
ตัวเลือกวัตถุ
ออบเจ็กต์ Option แสดงถึงองค์ประกอบ HTML <option>
เข้าถึงออบเจกต์ตัวเลือก
คุณสามารถเข้าถึง <option> องค์ประกอบโดยใช้ getElementById():
ตัวอย่าง
var x = document.getElementById("myOption");
เคล็ดลับ:คุณยังสามารถเข้าถึงออบเจ็กต์ Option โดยการค้นหาผ่าน คอลเลกชั่น องค์ประกอบ ของฟอร์ม หรือ คอลเลกชั่น ตัวเลือกของรายการดรอปดาวน์
สร้างออบเจ็กต์ตัวเลือก
คุณสามารถสร้าง <option> องค์ประกอบโดยใช้ document.createElement() วิธีการ:
ตัวอย่าง
var x = document.createElement("OPTION");
คุณสมบัติอ็อบเจ็กต์ตัวเลือก
Property | Description |
---|---|
defaultSelected | Returns the default value of the selected attribute |
disabled | Sets or returns whether an option is disabled, or not |
form | Returns a reference to the form that contains the option |
index | Sets or returns the index position of an option in a drop-down list |
label | Sets or returns the value of the label attribute of an option in a drop-down list |
selected | Sets or returns the selected state of an option |
text | Sets or returns the text of an option |
value | Sets or returns the value of an option to be sent to the server |
คุณสมบัติและเหตุการณ์มาตรฐาน
ออบเจ็กต์ Option ยังสนับสนุนคุณสมบัติและเหตุการณ์ มาตรฐาน อีกด้วย
หน้าที่เกี่ยวข้อง
อ้างอิง HTML: HTML <ตัวเลือก> แท็ก