HTML DOM Seleccionar colección opciones
Definición y Uso
opción para devolver la colección contiene toda la <opción> es una matriz elemento <select>.
Nota: Cada elemento de la matriz corresponde a una etiqueta <option> - a partir de 0.
gramática
selectObject.options
propiedad
属性 | 描述 |
---|---|
length | 返回集合的option元素数目 |
selectedIndex | 设置或者返回select对象已选选项的索引值。(以 0 起始) |
camino
方法 | 描述 |
---|---|
[index] | 以数字形式指定元素索引 (以 0 开始) |
[add(element[,index])] | 在集合中添加option元素 |
item(index) | 以数字索引返回集合中元素 |
namedItem(name) | 以名称为索引返回集合元素 |
remove(index) | 从集合中移除元素 |
Soporte para el navegador
Todos los principales navegadores soportan colección opciones
Ejemplos
Ejemplos
Ciclo de la lista desplegable de salida de todas las opciones:
<! DOCTYPE html>
<Html>
<Head>
<Charset Meta = "UTF-8">
<Title> Este tutorial (w3big.com) </ title>
<Script>
displayResult función () {
var x = document.getElementById ( "MySELECT");
var txt = "Todas las opciones:";
var i;
for (i = 0; i <x.length; i ++) {
txt = txt + "\ n" + x.options [i] .text;
}
alerta (txt);
}
</ Script>
</ Head>
<Cuerpo>
<Forma>
Su fruta favorita:
<Select id = "MySELECT">
<Opción> Apple </ option>
<Opción> Orange </ option>
<Opción> Piña </ option>
<Opción> plátano </ option>
</ Select>
</ Form>
<Botón type = "button" onclick = "displayResult ()"> para visualizar el texto de todas las opciones </ botón>
</ Body>
</ Html>
<Html>
<Head>
<Charset Meta = "UTF-8">
<Title> Este tutorial (w3big.com) </ title>
<Script>
displayResult función () {
var x = document.getElementById ( "MySELECT");
var txt = "Todas las opciones:";
var i;
for (i = 0; i <x.length; i ++) {
txt = txt + "\ n" + x.options [i] .text;
}
alerta (txt);
}
</ Script>
</ Head>
<Cuerpo>
<Forma>
Su fruta favorita:
<Select id = "MySELECT">
<Opción> Apple </ option>
<Opción> Orange </ option>
<Opción> Piña </ option>
<Opción> plátano </ option>
</ Select>
</ Form>
<Botón type = "button" onclick = "displayResult ()"> para visualizar el texto de todas las opciones </ botón>
</ Body>
</ Html>
Trate »
más ejemplos
Seleccionar objetos