如何使用JavaScript从下拉列表中删除选项?
要从下拉列表中删除选项,请使用remove()JavaScript中的方法。您可以尝试运行以下代码以了解如何从下拉菜单中删除选项-
示例
<!DOCTYPE html>
<html>
<body>
<form id = "myForm">
<select id = "selectNow">
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
<input type = "button" onclick = "remove()" value = "Click to Remove">
</form>
<p>Select and click the button to remove the selected option.</p>
<script>
function remove() {
var x = document.getElementById("selectNow");
x.remove(x.selectedIndex);
}
</script>
</body>
</html>热门推荐
10 女侠老师祝福语简短
11 感动妈妈的祝福语简短
12 宝宝祝福语诗意简短 古文
13 生日祝福语简短蛋糕上
14 送花简短有内涵祝福语
15 哥哥中考加油祝福语简短
16 宝宝100日简短祝福语
17 水晶婚夫妻祝福语简短
18 项目总生日祝福语简短