Objet d' option HTML DOM
Objet d'option
L'objet Option représente un élément HTML <option>.
Accéder à un objet d'option
Vous pouvez accéder à un élément <option> en utilisant getElementById() :
Exemple
var x = document.getElementById("myOption");
Conseil : Vous pouvez également accéder à un objet Option en effectuant une recherche dans la collection d' éléments d'un formulaire ou dans la collection d' options d'une liste déroulante.
Créer un objet d'option
Vous pouvez créer un élément <option> en utilisant la méthode document.createElement() :
Exemple
var x = document.createElement("OPTION");
Propriétés de l'objet d'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 |
Propriétés et événements standard
L'objet Option prend également en charge les propriétés et les événements standard .
Pages connexes
Référence HTML : balise HTML <option>