remove()メソッドを選択します
例
ドロップダウンリストから選択したオプションを削除します。
var x = document.getElementById("mySelect");
x.remove(x.selectedIndex);
定義と使用法
remove()メソッドは、ドロップダウンリストからオプションを削除するために使用されます。
ヒント:ドロップダウンリストにオプションを追加するには、add() メソッドを使用します。
ブラウザのサポート
Method | |||||
---|---|---|---|---|---|
remove() | Yes | Yes | Yes | Yes | Yes |
構文
selectObject.remove(index)
パラメータ値
Parameter | Description |
---|---|
index | Required. Specifies the index of the option to remove. Index starts at 0 |
技術的な詳細
戻り値: | 戻り値なし |
---|
その他の例
例
ドロップダウンリストからインデックス「2」のオプションを削除します。
var x = document.getElementById("mySelect");
x.remove(2);
例
ドロップダウンリストから最後のオプションを削除します。
var x = document.getElementById("mySelect");
if (x.length > 0) {
x.remove(x.length-1);
}
❮オブジェクトを選択