js日期联动

<script type="text/javascript">
function YYYYMMDDstart(year,month,day){
    MonHead = [31,28,31,30,31,30,31,31,30,31,30,31];
    for(var i=1920;i<=2020;i++){
        year.add(new Option(i,i));
    }
    for(var i=1;i<13;i++){
        month.add(new Option(i,i));
    }
    year.value = new Date().getFullYear();
    month.value = new Date().getMonth()+1;
    var n = MonHead[new Date().getMonth()];
    if(new Date().getMonth() == 1 && IsPinYear(year.value)){n++;}
    writeDay(n,day);
}
function YYYYDD(year,month,day){
    var n = MonHead[month.value-1];
    if(month.value == 2 && IsPinYear(year.value)) {n++;}
    day.options.length=0;
    writeDay(n,day);
}
function MMDD(year,month,day){
    var n = MonHead[month.value-1];
    if(month.value == 2 && IsPinYear(year.value)) {n++;}
    day.options.length=0;
    writeDay(n,day);
}
function IsPinYear(year){
    return (year%4 == 0&&(year%100!=0||year%400==0));
}
function writeDay(n,day){
    for(var i=1;i<(n+1);i++){
        day.add(new Option(i,i));
    }
}
YYYYMMDDstart(document.getElementById('SYear'),document.getElementById('SMonth'),document.getElementById('SDay'));
</script>

以上是js代码

<form name="forma" class="f14" method="post" action="#">阳历(公历)生日 
    			<select style="width:80px;" onchange="YYYYDD(document.forma.SYear,document.forma.SMonth,document.forma.SDay)" name="SYear" id="SYear">
    			</select> 年 
    			<select style="width:50px;" onchange="MMDD(document.forma.SYear,document.forma.SMonth,document.forma.SDay)" name="SMonth" id="SMonth">
    			</select> 月 
    			<select style="width:50px;" name="SDay" id="SDay" data="1">
    			</select> 日 	
</form>

以上是html代码




郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。