Cette traduction est incomplète. Aidez à traduire cet article depuis l'anglais.
L'interface HTMLSelectElement représente un élément HTML <select>. Cet élément partage aussi toute les propriétés et méthodes des autres elements HTML via l'interface HTMLElement.
Propriétés
Cette interface hérite des propriétés de HTMLElement, Element et Node.
HTMLSelectElement.autofocus- Est un
Booleanqui reflète l'attribut HTMLautofocus: il indique si l'élément a le focus au chargement de la page (excepté si l'utilisateur le change, par exemple en cliquant sur un autre element). Uniquement les elément associé à un formulaire dans le document peuvent utiliser cet attribut.
HTMLSelectElement.disabled- Est un
Booleanqui reflète l'attribut HTMLdisabled: il indique si l'élément est oui ou non desactivé. Si il est désactivé, l'élément n'accepte pas les clicks. HTMLSelectElement.formLecture seule- Retourne un
HTMLFormElementreprésentant le formulaire associé a cet élément. Si cet élément est le fils d'un formulaire, alors cet attribut est l'ID de l'element form. Si l'élément n'est pas fils d'un formulaire, alors l'attribut peut-être l'ID de n'importe quel élément du même document. HTMLSelectElement.labelsLecture seule- Retourne une
NodeListcontenant la liste des labels associé avec l'éléments select. HTMLSelectElement.length- Est un
unsigned longreprésentant le nombre d'élément<option>dans cet elementselect. HTMLSelectElement.multiple- Est un
Booleanreprésentant l'attribut HTMLmultiple, qui indique si plusieurs items peuvent être choisis à la fois par l'utilisateur. HTMLSelectElement.name- Est une
DOMStringqui représente l'attribut HTMLname, contenant le nom de ce contrôle pour les serveurs et pour les fonctions de recherche dans le DOM. HTMLSelectElement.optionsLecture seule- Returns a
HTMLOptionsCollectioncontaining the set of<option>elements contained by this element. HTMLSelectElement.required- Is a
Booleanthat reflects therequiredHTML attribute, which indicates whether the user is required to select a value before submitting the form. HTMLSelectElement.selectedIndex- Is a
longthat reflects the index of the first selected<option>element. The value-1indicates no element is selected. HTMLSelectElement.selectedOptionsLecture seule- Returns a live
HTMLCollectioncontaining the set of options that are selected. HTMLSelectElement.size- Is a
longthat reflects thesizeHTML attribute, which contains the number of visible items in the control. The default is 1, unlessmultipleis true, in which case it is 4. HTMLSelectElement.typeLecture seule- Returns a
DOMStringthe form control's type. Whenmultipleistrue, it returns"select-multiple"; otherwise, it returns"select-one". HTMLSelectElement.validationMessageLecture seule- Returns a
DOMStringcontaining a localized message that describes the validation constraints that the control does not satisfy (if any). This attribute is the empty string if the control is not a candidate for constraint validation (willValidateis false), or it satisfies its constraints. HTMLSelectElement.validityLecture seule- Returns a
ValidityStaterepresenting the validity state that this control is in. HTMLSelectElement.value- Is a
DOMStringwith the value of this form control, that is, of the first selected option. HTMLSelectElement.willValidateLecture seule- Is a
Booleanthat indicates whether the button is a candidate for constraint validation. It is false if any conditions bar it from constraint validation.
Méthodes
This interface inherits the methods of HTMLElement, and of Element and Node.
HTMLSelectElement.add()- Adds an element to the collection of
optionelements for thisselectelement. HTMLSelectElement.blur()- Removes input focus from this element. This method is now implemented on
HTMLElement. HTMLSelectElement.checkValidity()- Checks whether the element has any constraints and whether it satisfies them. If the element fails its constraints, the browser fires a cancelable
invalidevent at the element (and returnsfalse). HTMLSelectElement.focus()- Gives input focus to this element. This method is now implemented on
HTMLElement. HTMLSelectElement.item()- Gets an item from the options collection for this
<select>element. You can also access an item by specifying the index in array-style brackets or parentheses, without calling this method explicitly. HTMLSelectElement.namedItem()- Gets the item in the options collection with the specified name. The name string can match either the
idor thenameattribute of an option node. You can also access an item by specifying the name in array-style brackets or parentheses, without calling this method explicitly. HTMLSelectElement.remove()- Removes the element at the specified index from the options collection for this select element.
HTMLSelectElement.setCustomValidity()- Sets the custom validity message for the selection element to the specified message. Use the empty string to indicate that the element does not have a custom validity error.
Exemple
Get information about the selected option
/* assuming we have the following HTML <select id='s'> <option>First</option> <option selected>Second</option> <option>Third</option> </select> */ var select = document.getElementById('s'); // return the index of the selected option alert(select.selectedIndex); // 1 // return the value of the selected option alert(select.options[select.selectedIndex].value) // Second
Specifications
| Specification | Status | Comment |
|---|---|---|
| HTML Living Standard La définition de 'HTMLSelectElement' dans cette spécification. |
Standard évolutif | Since the latest snapshot, HTML5, it adds the autocomplete property and the reportValidity() method. |
| HTML5 La définition de 'HTMLSelectElement' dans cette spécification. |
Recommendation | Is a snapshot of HTML Living Standard. It adds the autofocus, form, required, labels, selectedOptions, willValidate, validity and validationMessage properties.The tabindex property and the blur() and focus() methods have been moved to HTMLElement.The methods item(), namedItem(), checkValidity() and setCustomValidity(). |
| Document Object Model (DOM) Level 2 HTML Specification La définition de 'HTMLSelectElement' dans cette spécification. |
Obsolete | options now returns an HTMLOptionsCollection.length now returns an unsigned long. |
| Document Object Model (DOM) Level 1 Specification La définition de 'HTMLSelectElement' dans cette spécification. |
Obsolete | Initial definition. |
Browser compatibility
Nous convertissons les données de compatibilité dans un format JSON.
Ce tableau de compatibilité utilise encore l'ancien format
car nous n'avons pas encore converti les données qu'il contient.
Vous pouvez nous aider en contribuant !
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|
| Basic support | 1.0 | 1.0 (1.7 ou moins) | 1.0 | 1.0 | 1.0 |
item() and namedItem() |
(Oui) | 4.0 (2.0) | ? | (Oui) | (Oui) |
setCustomValidity(), checkValidity(), willValidate, validationMessage, validity |
(Oui) | 4.0 (2.0) | ? | (Oui) | ? |
selectedOptions |
(Oui) | 26 (26) | ? | (Oui) | (Oui) |
labels |
(Oui) | Non implémenté (voir bug 556743) | ? | (Oui) | (Oui) |
| Feature | Android | Chrome | Firefox Mobile (Gecko) | Firefox OS | IE Phone | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|---|
| Basic support | 1.0 | 1.0 | 1.0 (1) | 1.0 | 1.0 | 1.0 | 1.0 |
item() and namedItem() |
? | ? | 4.0 (2.0) | 1.0 | ? | ? | (Oui) |
setCustomValidity(), checkValidity(), willValidate, validationMessage, validity |
? | ? | 4.0 (2.0) | 1.0 | ? | ? | ? |
selectedOptions |
? | ? | 26.0 (26) | 1.2 | ? | ? | (Oui) |
labels |
? | ? | Non implémenté (voir bug 556743) | Non implémenté (voir bug 556743) | ? | ? | (Oui) |
See also
- The
<select>HTML element, implementing this interface.
Étiquettes et contributeurs liés au document
Dernière mise à jour par :
mdnwebdocs-bot,