如何在js中给select 添加options?

document.getElementById("Mmonth").options.add(new Option(1, 1),0);
document.getElementById("Mmonth").options.add(new Option(1, 1));
都已经试过 火狐和google浏览器不支持 帮忙 谢谢

慕侠2389804
浏览 486回答 2
2回答

月关宝盒

我在火狐试了,我这没问题,代码<select id="Mmonth"><option>1</option></select><input type="button" onclick="a()" value="添加"/><script>function a(){document.getElementById("Mmonth").options.add(new Option(1, 1));}</script>

慕村225694

<script type="text/javascript">function addList(){var list = document.getElementById("list");var bb=["javascript1","javascript2","javascript3","javascript4"];for(var i = 0; i <bb.length; i++){var newOption = document.createElement("option");newOption.setAttribute("value", i);newOption.appendChild(document.createTextNode(bb[i]));list.appendChild(newOption);}}function clearList(){var list = document.getElementById("list");for(var i = list.options.length; i >= 0; i--){list.remove(i);}}</script></head><body><select name="list" id="list" style="width:120px"></select><input type="button" onclick="addList()" value="生成"/><input type="button" onclick="clearList()" value="清空" /></body>&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP