Latest web development tutorials

HTML DOM Pilih hapus () metode

Pilih Object Reference Pilih Objek

Definisi dan Penggunaan

Metode menghapus () digunakan untuk menghapus opsi dari daftar drop-down.

tatabahasa

selectObject.remove(index)

参数 描述
index 必需。规定要删除的选项的索引号。


Dukungan Browser

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Semua browser utama mendukung menghapus () metode


contoh

contoh

Contoh berikut mungkin menghapus opsi yang dipilih dari daftar:

<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> Tutorial ini (w3big.com) </ title>
<Script>
Fungsi removeOption () {
var x = document.getElementById ( "mySelect");
x.remove (x.selectedIndex);
}
</ Script>
</ Kepala>
<Body>

<Form>
<Pilih id = "mySelect">
<Pilihan> Apel </ option>
<Pilihan> Pear </ option>
<Pilihan> Banana </ option>
<Pilihan> Orange </ option>
</ Pilih>
<Input type = "button" onclick = "removeOption ()" value = "menghapus opsi">
</ Form>

</ Body>
</ Html>

Coba »


contoh

contoh yang lebih

Hapus opsi terakhir dari daftar drop-down


Pilih Object Reference Pilih Objek