帮忙看看,怎么改正确。

casear_huang 2002-07-25 07:46:59
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script>
function toDate1(){
with(document.all){
vYear=parseInt(year.options[year.selectedIndex].text)
alert(year.selectedIndex);
vMonth=parseInt(month.options[month.selectedIndex].text)
day.length=0;
for(i=0;i<(new Date(vYear,vMonth,0)).getDate();i++){
day.options[day.length++].value=day.length;
day.options[day.length-1].text=day.length;
}
}
}
window.onload=toDate;
</script>
</head>

<body>
<form>
<select id=year onchange=toDate()>
<script>for(i=1970;i<=2010;i++)document.write("<option>"+i+"</option>")</script>
</select>
<select id=month onchange=toDate()>
<script>for(i=1;i<=12;i++)document.write("<option>"+i+"</option>")</script>
</select>
<select id=day></select></form>
</body>
</html>
...全文
58 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
JavaCoffee 2002-07-25
  • 打赏
  • 举报
回复
给你看一下我以前写过的这个例子吧:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>日期选择</title>
<Script>
function addDays()
{
var febdates,yearPart,monthPart,i,strHTML;
yearPart=parseInt(document.all.bYear.value);
monthPart=parseInt(document.all.bMonth.value);
i=1;
strHTML="<select name='bDay' id='bDay' size='1'>";
while (monthPart==1 || monthPart==3 || monthPart==5 || monthPart==7 || monthPart==8 || monthPart==10 || monthPart==12)
{
while (i<=31)
{
strHTML= strHTML + "<option value='"+i+"'>"+i+"</option>";
i++;
}
strHTML=strHTML + "</select>";
selection.innerHTML=strHTML;
break;
}
while (monthPart==4 || monthPart==6 || monthPart==9 || monthPart==11)
{
while (i<=30)
{
strHTML= strHTML + "<option value='"+i+"'>"+i+"</option>";
i++;
}
strHTML=strHTML + "</select>";
selection.innerHTML=strHTML;
break;
}
while (monthPart==2)
{
if (yearPart % 4==0 && yearPart % 100 !=0 || yearPart % 400==0)
febdates=29;
else
febdates=28;
while (i<=febdates)
{
strHTML= strHTML + "<option value='"+i+"'>"+i+"</option>";
i++;
}
strHTML=strHTML + "</select>";
selection.innerHTML=strHTML;
break;
}
}
</Script>
</head>

<body>
<table>
<tr>
<td>出生日期:
<form name="frmdate">
<select name="bYear" size="1" id="bYear" onchange="addDays();">
<Script>
date=new Date();
tYear=date.getYear();
i=tYear-25;
document.write("<option></option> ");
while (i<=tYear)
{
document.write("<option value=\""+i+"\">"+i+"</option>");
i++;
}
</Script>
</select>

<select name="bMonth" id="bMonth" size="1" onchange="addDays();">
<Script>
i=1
document.write("<option></option> ");
while (i<=12)
{
document.write("<option value=\""+i+"\">"+i+"</option>");
i++;
}
</Script>
</select>

<span id="selection"><select id="bDay" name="bDay" size=1></select></span>


</form>
</td></tr>
</body>

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧