三级联动,之前那个代码太难看了 在更新一下

<body>
年<select id="a"></select>
月<select id="b">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
</select>
日<select id="c">

</select>
</body>
</html>
<script>
a=document.getElementById("a");
b=document.getElementById("b");
c=document.getElementById("c");

a.onblur=function(){
aa=a.value;
}

for(x=1900;x<=2017;x++){
a.options.add(new Option(x))
}

b.onblur=function(){

if(b.value==2&&((aa%4==0&&aa%100!=0)||aa%400==0)){

for(x=1;x<=29;x++){

e=document.createElement("option")
e.innerHTML=x;
c.appendChild(e);
}
}

else if(b.value==2&&((aa%4!=0&&aa%100==0)||aa%400!=0)){
for(x=1;x<=28;x++){

e=document.createElement("option")
e.innerHTML=x;
c.appendChild(e);
}
}

else if(b.value==1||b.value==3||b.value==5||b.value==7||b.value==8||b.value==10||b.value==12){
for(x=1;x<=31;x++){

e=document.createElement("option")
e.innerHTML=x;
c.appendChild(e);
}
}

else if(b.value==4||b.value==6||b.value==9||b.value==11)
for(x=1;x<=30;x++){

e=document.createElement("option")
e.innerHTML=x;
c.appendChild(e);
}


}

</script>

原文地址:https://www.cnblogs.com/m110/p/7612514.html