كائن خيار HTML DOM
كائن الخيار
يمثل كائن الخيار عنصر <خيار> HTML.
الوصول إلى كائن الخيارات
يمكنك الوصول إلى عنصر <option> باستخدام getElementById ():
مثال
var x = document.getElementById("myOption");
تلميح: يمكنك أيضًا الوصول إلى كائن الخيار من خلال البحث في مجموعة عناصر النموذج ، أو مجموعة الخيارات لقائمة منسدلة.
قم بإنشاء كائن الخيار
يمكنك إنشاء عنصر <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 |
الخصائص القياسية والأحداث
يدعم كائن الخيار أيضًا الخصائص والأحداث القياسية .
الصفحات ذات الصلة
مرجع HTML: علامة <خيار> HTML