javascript向select或DropDownList中如何添加数据?
javascript向select或DropDownList中如何添加数据?varmz=["甲","乙","丙","丁"];for(vari=0;i<mz.length;...
javascript向select或DropDownList中如何添加数据? var mz = ["甲","乙","丙","丁"];
for(var i=0;i<mz.length;i++)
{
var varItem = new Option(mz[i], i);
document.getElementById("MySelect").options.add(varItem);
} 展开
for(var i=0;i<mz.length;i++)
{
var varItem = new Option(mz[i], i);
document.getElementById("MySelect").options.add(varItem);
} 展开
1个回答
2013-06-09
展开全部
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns=" http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function AddNum(){
var o=document.getElementById("Select1");
var varItem=new Option("添加的丁","3");//要添加的选项
o.options.add(varItem);//添加选项
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<select id="Select1">
<option>甲</option>
<option selected="selected">乙</option>
<option>丙</option>
</select>
<input id="Button1" type="button" value="添加" onclick="AddNum();" />
</div>
</form>
</body>
</html>
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function AddNum(){
var o=document.getElementById("Select1");
var varItem=new Option("添加的丁","3");//要添加的选项
o.options.add(varItem);//添加选项
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<select id="Select1">
<option>甲</option>
<option selected="selected">乙</option>
<option>丙</option>
</select>
<input id="Button1" type="button" value="添加" onclick="AddNum();" />
</div>
</form>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询