以下是写在增加也面的代码:
<html:select property="year" onchange="toDate()">
<script language="JavaScript">...for(i=1975;i<=2035;i++)document.write("<option>"+i+"</option>")</script>
</html:select>年
<html:select property="month" onchange="toDate()">
<script language="JavaScript">...for(i=1;i<=12;i++)document.write("<option>"+i+"</option>")</script>
</html:select>月
<html:select property="day"></html:select>日
<script language="JavaScript">...
//<!--
function toDate()...{
with(document.all)...{
vYear=parseInt(year.options[year.selectedIndex].text)
vMonth=parseInt(month.options[month.selectedIndex].text)
day.length=0;
for(i=0;i<(new Date(vYear,vMonth,0)).getDate();i++)...{day.options[day.length++].value=day.length;day.options[day.length-1].text=day.length;}
}
}
window.onload=toDate;
//-->
</script>以下是修改也面的代码:
<html:select property="year" onchange="toDate()">
<script language="JavaScript">...
for(i=1975;i<=2035;i++)...{
if(i==$...{leagueEditActionForm.year})...{document.write("<option selected>"+i+"</option>");}
else...{document.write("<option>"+i+"</option>");}
}
</script>
</html:select>年
<html:select property="month" onchange="toDate()">
<script language="JavaScript">...
for(i=1;i<=12;i++)...{
if(i==$...{leagueEditActionForm.month})...{document.write("<option selected>"+i+"</option>");}
else...{document.write("<option>"+i+"</option>");}
}
</script>
</html:select>月
<html:select property="day"></html:select>日
<script language="JavaScript">...
//<!--
function toDate()...{
with(document.all)...{
vYear=parseInt(year.options[year.selectedIndex].text)
vMonth=parseInt(month.options[month.selectedIndex].text)
day.length=0;
for(i=0;i<(new Date(vYear,vMonth,0)).getDate();i++)...{day.options[day.length++].value=day.length;day.options[day.length-1].text=day.length;}
day.options.value=$...{leagueEditActionForm.day};
}
}
window.onload=toDate;
//-->
</script>
本文介绍了一个使用HTML和JavaScript实现的日期选择器。该选择器能够动态生成年份、月份选项,并根据所选年份和月份自动更新对应天数的选项。

5948

被折叠的 条评论
为什么被折叠?



