细心
<body>
<select id="slt1" size="1" style="width: 100px;">
</select>
<select id="slt2" size="1" style="width: 100px;">
</select>
<select id="slt3" size="1" style="width: 100px;">
</select>
</body>
</html>
<script>
// document.getElementById('slt1').onchange = function() {
var slt1 = document.getElementById('slt1');
var slt2 = document.getElementById('slt2');
var slt3 = document.getElementById('slt3');
for(i=1990;i<=2017;i++){
var year=document.createElement("option");
year.innerText=i;
slt1.appendChild(year)
}
for(j=1;j<=12;j++){
var month=document.createElement("option");
month.innerText=j;
slt2.appendChild(month)
}
for(k=1;k<=31;k++){
var day=document.createElement("option");
day.innerText=k;
slt3.appendChild(day)
}
slt2.onchange = function(){
y=slt1.selectedOptions[0].value
m=slt2.selectedOptions[0].value;
slt3.options[28].style.display="inline"
slt3.options[29].style.display="inline"
slt3.options[30].style.display="inline"
if(y%4==0&&y%100!=0||y%400==0){
if(m==2){
slt3.options[30].style.display="none"
slt3.options[29].style.display="none"
}else{
if(m==4||m==6||m==9||m==11){
slt3.options[30].style.display="none"
}
}
}else{
if(m==2){
slt3.options[30].style.display="none"
slt3.options[29].style.display="none"
slt3.options[28].style.display="none"
}
else{
if(m==4||m==6||m==9||m==11){
slt3.options[30].style.display="none"
}
}
}
}
一开始总是没出效果,查了好长时间才发现少了一半括号。改了发现日期对不上原来是OPTION的O不能是大写,这些小问题容易被忽略,但却好重要。