我通过Google Apps脚本提供网页,但无法从HTMLSelectElement中删除选项。当我按下按钮拨打select.remove(0);
时,我收到错误'undefined' is not a function (evaluating 'select.remove(0)')
。我正在运行Safari,但也尝试过(使用类似的结果)使用Firefox。代码如下。
<html>
<head>
<script>
function removeFirstOption(){
var select = document.getElementById("mySelect");
alert(select); //This returns "[object HTMLSelectElement]"
select.remove(0);
}
</script>
</head>
<body>
<select id="mySelect" name="mySelect">
<option value="nothing">Nothing to Display</option>
</select>
<button onclick="removeFirstOption()">Remove First One</button>
</body>
</html>
我也尝试了.empty()
,但是抛出了同样的错误。提前谢谢!