HTML DOM properti Indeks Option
Definisi dan Penggunaan
Properti mengembalikan daftar drop-down indeks pilihan dalam indeks.
indeks dimulai dari 0.
tatabahasa
Pengaturan properti Indeks:
optionObject.index=integer
Pengembalian sifat indeks:
optionObject.index
Dukungan Browser
Semua browser utama mendukung atribut Indeks
contoh
contoh
Contoh ini mengembalikan posisi indeks dari daftar drop-down dari opsi yang dipilih:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> Tutorial ini (w3big.com) </ title>
<Script>
Fungsi displayResult () {
var x = document.getElementById ( "mySelect") SelectedIndex .;
var y = document.getElementById ( "mySelect") Pilihan .;
alert ( "Index:" + y [x] .index + "adalah" + y [x] .text);
}
</ Script>
</ Kepala>
<Body>
<Form>
Pilih buah favorit Anda:
<Pilih id = "mySelect">
<Pilihan> Apel </ option>
<Pilihan> Orange </ option>
<Pilihan> Pineapple </ option>
<Pilihan> Banana </ option>
</ Pilih>
</ Form>
<Tombol type = "button" onclick = "displayResult ()"> Indeks display </ button>
</ Body>
</ Html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> Tutorial ini (w3big.com) </ title>
<Script>
Fungsi displayResult () {
var x = document.getElementById ( "mySelect") SelectedIndex .;
var y = document.getElementById ( "mySelect") Pilihan .;
alert ( "Index:" + y [x] .index + "adalah" + y [x] .text);
}
</ Script>
</ Kepala>
<Body>
<Form>
Pilih buah favorit Anda:
<Pilih id = "mySelect">
<Pilihan> Apel </ option>
<Pilihan> Orange </ option>
<Pilihan> Pineapple </ option>
<Pilihan> Banana </ option>
</ Pilih>
</ Form>
<Tombol type = "button" onclick = "displayResult ()"> Indeks display </ button>
</ Body>
</ Html>
Coba »
opsi Object