日期:2009-08-20  浏览次数:21068 次

<select id=I_Year>
</select>年
<select id=I_Mon onChange="seleDate('mon')">

</select>月
<select id=I_Date onChange="seleDate('date')">
</select>日

<script>
function genYear(sele,year,length) {
  var d = new Date();
  for(i=0;i<length;i++) {
    sele.options[i] = new Option(i+year,i+year)
    if(i+year == d.getYear())
      n = i;
  }
  sele.options.length = length;
  sele.options[n].selected = true;
}

function genMon(sele,year) {
  var d = new Date();
  for(i=0;i<12;i++) {
    sele.options[i] = new Option(i+1,i+1)
    if(i == d.getMonth())
      n = i;
  }
  sele.options.length = 12;
  sele.options[n].selected = true;
}

function genDate(sele,year,month) {
  var d = new Date(year,month,0);
  var length = d.getDate();
  d = new Date();
  for(i=0;i<=length;i++) {
    sele.options[i] = new Option(i+1,i+1)
    if(i+1 == d.getDate())
      n = i;
  }
  sele.options.length = length;
  sele.options[n].selected = true;
}
var d = new Date();
genYear(I_Year,1993,20);
genMon(I_Mon,d.getYear());
genDate(I_Date,d.getYear(),d.getMonth()+1);

function seleDate(mode) {
  switch(mode) {
    case "mon":
      genDate(I_Date,
        I_Year.options[I_Year.selectedIndex].value,
        I_Mon.options[I_Mon.selectedIndex].value);
      break;
    case "date":
      alert(I_Year.options[I_Year.selectedIndex].value+"-"+
        I_Mon.options[I_Mon.selectedIndex].value+"-"+
        I_Date.options[I_Date.selectedIndex].value);
  }
}
</SCRIPT>