<script>
function chanday()
{
var days=31;
if(document.getElementById('selMonth').value==04||document.getElementById('selMonth').value==06||document.getElementById('selMonth').value==09||document.getElementById('selMonth').value==11)
days=30;
else if(document.getElementById('selMonth').value==02)
{
Nowyear=document.getElementById('selYear').value ;
if((Nowyear%4==0 &&Nowyear%100!=0) || Nowyear%400==0)
days=29;
else
days=28;
}
flen=document.getElementById('selDay').length;
if(flen > days && document.getElementById('selDay').selectedIndex >= days - 1)
document.getElementById('selDay').selectedIndex = days - 1;
document.getElementById('selDay').length =days;
for(i=flen+1;i<=days;i++)
{
document.getElementById('selDay').options(i-1).text=i;
document.getElementById('selDay').options(i-1).value=i;
}
document.getElementById('selDate').value = document.getElementById('selYear').value + "/" + document.getElementById('selMonth').value + "/" + document.getElementById('selDay').value;
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<input id=selDate type=hidden value="1980/1/1" runat=server >
<select id=selYear οnchange="chanday()">
<script>
for(var i=1900;i<2006;i++)
{
if(i == 1980)
document.write("<option value='" + i + "' selected>" + i + "</option>");
else
document.write("<option value='" + i + "'>" + i + "</option>");
}
</script>
</select>
<select id=selMonth οnchange="chanday()">
<script>
for(var i=1;i<=12;i++)
{
document.write("<option value='" + i + "'>" + i + "</option>");
}
</script>
</select>
<select id=selDay οnchange="chanday()">
<script>
for(var i=1;i<31;i++)
{
document.write("<option value='" + i + "'>" + i + "</option>");
}
</script>
</select>
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 168px; POSITION: absolute; TOP: 192px" runat="server"
Text="Button"></asp:Button>
</form>
</body>
</HTML>
后台
private void Button1_Click(object sender, System.EventArgs e)
{
DateTime dt = DateTime.Parse(Request.Form["selDate"]);
Response.Write(dt.ToString());
}
完整代码到这里下载
http://www.cnblogs.com/Files/Truly/DateDropDown.rar