HTML DOM Select collection d'options
Définition et utilisation
possibilité de retourner la collection contient toutes les <option> est un tableau élément <select>.
Remarque: Chaque élément du tableau correspond à une balise <option> - à partir de 0.
grammaire
selectObject.options
propriété
属性 | 描述 |
---|---|
length | 返回集合的option元素数目 |
selectedIndex | 设置或者返回select对象已选选项的索引值。(以 0 起始) |
manière
方法 | 描述 |
---|---|
[index] | 以数字形式指定元素索引 (以 0 开始) |
[add(element[,index])] | 在集合中添加option元素 |
item(index) | 以数字索引返回集合中元素 |
namedItem(name) | 以名称为索引返回集合元素 |
remove(index) | 从集合中移除元素 |
support du navigateur
Tous les principaux navigateurs prennent en charge la collecte des options
Exemples
Exemples
Cycle de la liste de sortie déroulante de toutes les options:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Titre> Ce tutoriel (w3big.com) </ title>
<Script>
fonction displayResult () {
var x = document.getElementById ( "MySELECT");
var txt = "Toutes les options:";
var i;
for (i = 0; i <x.length; i ++) {
txt = txt + "\ n" + x.options [i] .text;
}
alerte (txt);
}
</ Script>
</ Head>
<Body>
<Form>
Votre fruit préféré:
<Sélectionnez id = "MySELECT">
<Option> Apple </ option>
<Option> Orange </ option>
<Option> Ananas </ option>
<Option> Banana </ option>
</ Select>
</ Form>
<Bouton type = "button" onclick = "displayResult ()"> pour afficher le texte de toutes les options </ button>
</ Body>
</ Html>
<Html>
<Head>
<Meta charset = "utf-8">
<Titre> Ce tutoriel (w3big.com) </ title>
<Script>
fonction displayResult () {
var x = document.getElementById ( "MySELECT");
var txt = "Toutes les options:";
var i;
for (i = 0; i <x.length; i ++) {
txt = txt + "\ n" + x.options [i] .text;
}
alerte (txt);
}
</ Script>
</ Head>
<Body>
<Form>
Votre fruit préféré:
<Sélectionnez id = "MySELECT">
<Option> Apple </ option>
<Option> Orange </ option>
<Option> Ananas </ option>
<Option> Banana </ option>
</ Select>
</ Form>
<Bouton type = "button" onclick = "displayResult ()"> pour afficher le texte de toutes les options </ button>
</ Body>
</ Html>
Essayez »
D'autres exemples
Aussi à travers un menu déroulant Options pour modifier les options du menu déroulant en cours.
Sélectionner des objets