Latest web development tutorials

propiedad HTML DOM Seleccionar selectedIndex

Select Object Reference Seleccionar objetos

Definición y Uso

selectedIndex conjuntos de propiedades o devuelve el número de índice de la lista desplegable de las opciones seleccionadas.

Nota: Si se permite realizar varias selecciones, a continuación, sólo devuelve el primer número de índice de la opción seleccionada.

gramática

Configuración de las propiedades selectedIndex:

selectObject.selectedIndex=integer

propiedad de nuevo selectedIndex:

selectObject.selectedIndex


Soporte para el navegador

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Todos los principales navegadores soportan propiedad selectedIndex


Ejemplos

Ejemplos

Los siguientes ejemplos indican el número de índice de la opción seleccionada:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
    var x=document.getElementById("mySelect").selectedIndex;
    var y=document.getElementById("mySelect").options;
    alert("索引: " + y[x].index + " is " + y[x].text);
}
</script>
</head>
<body>

<form>
选择你最喜欢的水果:
<select id="mySelect">
    <option>Apple</option>
    <option>Orange</option>
    <option>Pineapple</option>
    <option>Banana</option>
</select>
</form>
<button type="button" onclick="displayResult()">显示索引</button>

</body>
</html>

Trate »


Select Object Reference Seleccionar objetos