<div style="width:600px; height:100px;">
<select id="year">
</select>
年
<select id="month" onchange="FillDay()">
</select>
月
<select id="day">
</select>
日
</div>
</body>
<script type="text/javascript">
FillYear();
FillMonth();
FillDay();
function FillYear()
{
var sj = new Date();
var nian = sj.getFullYear();
var s = "";
for(var i=nian-5;i<nian+6;i++)
{
if(i==nian)
{
s +="<option selected=‘selected‘>"+i+"</option>";
}
else
{
s +="<option>"+i+"</option>";
}
}
document.getElementById("year").innerHTML = s;
}
function FillMonth()
{
var sj = new Date();
var yue = sj.getMonth()+1;
var s = "";
for(var i=1;i<13;i++)
{
if(i==yue)
{
s +="<option selected=‘selected‘>"+i+"</option>";
}
else
{
s +="<option>"+i+"</option>";
}
}
document.getElementById("month").innerHTML=s;
}
function FillDay()
{
var sj = new Date();
var tian = sj.getDate();
//取月份求天数
var yue = document.getElementById("month").value;
var n = 31;
if(yue==4 || yue==6 ||yue==9 ||yue==11)
{
n = 30;
}
else if(yue==2)
{
n=28;
}
//用循环添加
var s = "";
for(var i=1;i<n+1;i++)
{
if(i==tian)
{
s +="<option selected=‘selected‘>"+i+"</option>";
}
else
{
s +="<option>"+i+"</option>";
}
}
document.getElementById("day").innerHTML = s;
}
function Dan()
{
//把列表1选中值取出
var list1 = document.getElementById("list1");
var v = list1.value;
//造一个option项
var s = "<option class=‘o2‘>"+v+"</option>";
//判断list2里面是否有该项
var attr = document.getElementsByClassName("o2");
var cz = true;
for(var i=0;i<attr.length;i++)
{
//alert(attr[i].innerHTML);
if(attr[i].innerHTML==v)
{
cz = false;
break;
}
}
if(cz)
{
//将option项扔到list2
var list2 = document.getElementById("list2");
list2.innerHTML +=s;
}
}
function Duo()
{
document.getElementById("list2").innerHTML = document.getElementById("list1").innerHTML;
}
</script>
</html>