Javascript in Firefox

2007-04-14 7:46 am
select1 = document.MainForm.selStatus;
var size = select1.length;
for (var i = size-1; i >= 0; i--)
{
// remove won't work with Netscape 7, Firefox
select1.options.remove(i);
}

The above codes to remove all options in a html select control work in IE but not Firefox. How can the options in a html select control be removed?

回答 (1)

2007-04-14 8:30 am
✔ 最佳答案
用以下語法, 應大部份瀏覽器都可行,
select1.options.remove(i) 應改為select1.remove(i)
範例如下,
<html>
<head>
<script type="text/javascript">
function removeOption()
{
var x=document.getElementById("mySelect")
x.remove(x.selectedIndex)
}
</script>
</head>
<body><form>
<select id="mySelect">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
<input type="button" onclick="removeOption()"
value="Remove option">
</form></body>
</html>如解答到閣下問題, 煩請負評以下自問自答用戶,

http://hk.knowledge. yahoo.com/my/profile _answer_best?show=HA 00005994&cp=11&a mp;tp=89&


收錄日期: 2021-04-23 21:30:12
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070413000051KK06793

檢視 Wayback Machine 備份