js中给select 添加options
document.getElementById("Mmonth").options.add(newOption(1,1),0);document.getElementBy...
document.getElementById("Mmonth").options.add(new Option(1, 1),0);
document.getElementById("Mmonth").options.add(new Option(1, 1));
都已经试过 火狐和google浏览器不支持 帮忙 谢谢 展开
document.getElementById("Mmonth").options.add(new Option(1, 1));
都已经试过 火狐和google浏览器不支持 帮忙 谢谢 展开
3个回答
展开全部
<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>
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>
展开全部
我在火狐试了,我这没问题,代码
<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>
<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>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<select id="Mmonth">
<option>1</option>
</select>
<script>
var selectId = document.getElementById("Mmonth"),i=0;
selectId.onclick = function(){
i = i +1
this.options.add(new Option("new content"+i,2))
}
</script>
这样是可以添加的,你new Option第一个内容,第二个是option选项索引!
<option>1</option>
</select>
<script>
var selectId = document.getElementById("Mmonth"),i=0;
selectId.onclick = function(){
i = i +1
this.options.add(new Option("new content"+i,2))
}
</script>
这样是可以添加的,你new Option第一个内容,第二个是option选项索引!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询