【发个小分:如何在前台javascript添加dropdownlist里的项?】 比如说我要在dropdownlist里添加1975-2000的年份,怎么样在javascript中通过循环添加数据?js该怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 d = document.getElementById('<%=dropdownlistID.ClientID%>')for(i = 1975,i<=2000;i++)d.options[d.options.length] = new Option(i,i) 服务器 端使用Request.Form[dropdownlistID.UniqueID]得到 <script language="javascript" type="text/javascript"> function getdate() { var d = document.getElementById("year"); for(i = 1975,i<=2000;i++) { d.options[d.options.length] = new option(i,i); } </script></head><body onload="getdate()"> <form id="form1" runat="server"> <div> <asp:DropDownList ID="year" runat="Server"></asp:DropDownList>年 <asp:DropDownList ID="month" runat="Server"></asp:DropDownList>月 <asp:DropDownList ID="day" runat="server"></asp:DropDownList>日 </div> </form></body>这样错的原因是什么? <script type="text/javascript">d = document.getElementById('<%=dropdownlistID.ClientID%>')for(i = 1975,i<=2000;i++) d.options.add(new Option(i,i);</script> Form1.drpproj.add(new Option(text,value)); sonce8() ------正解! <body onload="getdate()"> <form id="form1" runat="server"> <div> <asp:DropDownList ID="year" runat="Server"></asp:DropDownList>年 <asp:DropDownList ID="month" runat="Server"></asp:DropDownList>月 <asp:DropDownList ID="day" runat="server"></asp:DropDownList>日 </div><script language="javascript" type="text/javascript"> function getdate() { var d = document.getElementById("year"); for(i = 1975;i<=2000;i++) { d.Options.add(new Option(i,i)); } } </script> </form></body> for(i = 1975,i<=2000;i++)//,应该为; LZ的错误还有js代码应该放到下拉框后面。 DropDownList.options.add(new Option("value",index)); Form1.drpproj.options.length=0;来清空 高手们帮忙看下,二进制问题!谢谢 DIV文本控制问题 求一正则表达式 asp.net 中GridView如何实现购物车 分层开发的一点想法 怎样在后台修改IE的URL 安装MSDN时出错! asp.net中字体设置的问题?明明字号是smaller,为什么显示的时候却那么大? 如何保存用HttpWebResponse获取的图片? 请教:查询数据库的语句问题 请问VS2003连sqlserver2005怎么连??? 大家帮忙看一下。给存储过程传参数时报错。
for(i = 1975,i<=2000;i++)
d.options[d.options.length] = new Option(i,i)
Request.Form[dropdownlistID.UniqueID]得到
function getdate()
{
var d = document.getElementById("year");
for(i = 1975,i<=2000;i++)
{
d.options[d.options.length] = new option(i,i);
}
</script>
</head>
<body onload="getdate()">
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="year" runat="Server"></asp:DropDownList>年
<asp:DropDownList ID="month" runat="Server"></asp:DropDownList>月
<asp:DropDownList ID="day" runat="server"></asp:DropDownList>日
</div>
</form>
</body>这样错的原因是什么?
d = document.getElementById('<%=dropdownlistID.ClientID%>')
for(i = 1975,i<=2000;i++)
d.options.add(new Option(i,i);
</script>
------
正解!
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="year" runat="Server"></asp:DropDownList>年
<asp:DropDownList ID="month" runat="Server"></asp:DropDownList>月
<asp:DropDownList ID="day" runat="server"></asp:DropDownList>日
</div><script language="javascript" type="text/javascript">
function getdate()
{
var d = document.getElementById("year");
for(i = 1975;i<=2000;i++)
{
d.Options.add(new Option(i,i));
}
}
</script>
</form>
</body>