码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-09-29 21:09:09      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:fun   value   html   select   element   append   tee   inner   三级联动   

<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>

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

标签:fun   value   html   select   element   append   tee   inner   三级联动   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!