HTML DOM bentuk Option properti
Definisi dan Penggunaan
bentuk properti mengembalikan referensi ke bentuk yang berisi pilihan.
Properti ini mengembalikan objek bentuk.
tatabahasa
optionObject.form
Dukungan Browser
Semua browser utama mendukung sifat bentuk
contoh
contoh
Contoh ini mengembalikan daftar drop-down pilihan bentuk pemilik dipilih id:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> Tutorial ini (w3big.com) </ title>
<Script>
Fungsi displayResult () {
var x = document.getElementById ( "mySelect") form.id .;
alert (x);
}
</ Script>
</ Kepala>
<Body>
<Form id = "form1">
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 ()"> display milik bentuk ID </ button>
</ Body>
</ Html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> Tutorial ini (w3big.com) </ title>
<Script>
Fungsi displayResult () {
var x = document.getElementById ( "mySelect") form.id .;
alert (x);
}
</ Script>
</ Kepala>
<Body>
<Form id = "form1">
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 ()"> display milik bentuk ID </ button>
</ Body>
</ Html>
Coba »
opsi Object