作业讲解:
1.两个列表之间移动数据
<select id="x" size="12" style="width:200px">
<option>黑椒牛排七分熟</option>
<option>菠萝三文鱼</option>
<option>薄荷蔬菜沙拉</option>
<option>西红柿酱汁意面</option>
<option>意式薄饼</option>
<option>奶油牛肉丁番茄汤</option>
<option>智利佳美娜一瓶</option>
</select>
<input type="submit" value=">>" onclick="Yd()" />
<input type="submit" value="->" onclick="Qb()" />
<select id="y" size="12" style="width:200px">
<option>美味的西餐</option>
</select>
function Yd()
{
var a=document.getElementById("x").value;
var attr=document.getElementsByClassName("m");
var cz=true;
for(var i=0;i<attr.length;i++)
{
if(attr[i].innerHTML==a)
{
cz=false;
break;
}
}
if(cz)
{
var b=document.getElementById("y");
b.innerHTML+="<option class=‘m‘>"+a+"</option>";
}
}
function Qb()
{
var a=document.getElementById("x");
var list=document.getElementById("y");
list.innerHTML =list.innerHTML + a.innerHTML;
}
2.日期时间选择
<div style="width:600px; height:100px">
<select id="year">
</select>年
<select id="month" onchange="FillDay()">
</select>月
<select id="day">
</select>日
</div>
<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 FillFillMonth()
{
var sj=new Date();
var yue=sj.getFullMonth()+1;
var s="";
for(var i=1;i<13;i++)
{
if(i==nian)
{
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==nian)
{
s+="<option selected=‘selected‘>"+i+"</option>";
}
else
{
s+="<option>"+i+"</option>";
}
document.getElementById("month").innerHTML=s;
}
</script>