Latest web development tutorials

HTML DOM propriété index Option

Option Object Reference Option Object

Définition et utilisation

propriété renvoie la liste déroulante index des options de l'indice.

L'indice commence à 0.

grammaire

Définition des propriétés d'index:

optionObject.index=integer

Renvoie des propriétés d'index:

optionObject.index


support du navigateur

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Tous les principaux navigateurs prennent en charge l'attribut index


Exemples

Exemples

Cet exemple renvoie la position d'index de la liste déroulante des options sélectionnées:

<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Titre> Ce tutoriel (w3big.com) </ title>
<Script>
fonction displayResult () {
var x = document.getElementById ( "MySELECT") selectedIndex .;
var y = document.getElementById ( "MySELECT") Options .;
alert ( "Index:" + y [x] .index + "est" + y [x] .text);
}
</ Script>
</ Head>
<Body>

<Form>
Choisissez 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 ()"> index d'affichage </ button>

</ Body>
</ Html>

Essayez »


Option Object Reference Option Object