我正在通过 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()
了,但还是抛出了同样的错误。提前致谢!