javascript 编程题
发布网友
发布时间:2022-06-01 05:14
我来回答
共1个回答
热心网友
时间:2023-11-24 05:20
<script>
var s_y,s_m,s_d;
function initSelectDate(d){
var curDate=new Date();
if (d!=null&&d.length>0)
curDate=new Date(d.replace(/-/gi,"/"))
s_y=document.getElementById("s_y");
s_m=document.getElementById("s_m");
s_d=document.getElementById("s_d");
for (var i=1970;i<2050;i++){
s_y.options.add(new Option(i,i))
}
for (var i=1;i<=12;i++){
s_m.options.add(new Option(i,i));
}
s_y.onchange=function(){changeDate()};
s_y.value=curDate.getFullYear();
s_m.onchange=function(){changeDate()};
s_m.value=curDate.getMonth()+1;
changeDate(curDate.getDate())
}
function changeDate(defaultDate){
var t;
if (isFinite(defaultDate))
t=defaultDate;
else
t=s_d.value;
s_d.options.length=0;
var j=0;
switch(parseInt(s_m.value,10)){
case 4:
case 6:
case 9:
case 11:
j=30;
break;
case 2:
var y=s_y.value;
if (y%4==0&&y%100!=0||y%400==0)
j=29;
else
j=28;
break;
default:
j=31;
}
for (var i=1;i<=j;i++)
s_d.options.add(new Option(i,i));
if (t!=""){
if (t>j)
s_d.value=j;
else
s_d.value=t;
}
else
s_d.value=new Date().getDate();
}
var curDate=new Date();
window.onload=function(){initSelectDate(curDate);}
</script>
出生年月:
<select id="s_y" name="sltYear"></select>年
<select id="s_m" name="sltMonth"><select>月
<select id="s_d" name="sltDay"></select>日