第一种
<script>
var year =prompt("请输入一个年份")
if(year!=null)
{
var a=isNaN(year)
if(a==false)
{
if(year%1==0&&year>0&&year<9999)
{
var month=prompt("请输入月份")
if(month!=null)
{
var b=isNaN(month)
if(b==false)
{
if(month%1==0&&month>0&&month<=12)
{
var day=prompt("请输入天数")
if(day!=null)
{
var c=isNaN(day)
if(c==false)
{
if(day%1==0&&day>0&&day<=31)
{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{
alert(year+"-"+month+"-"+day)
}
else if(month==4||month==6||month==9||month==11)
{
alert(year+"-"+month+"-"+day)
}
else(month==2)
{
if(year%4==0&&year%100!=0||year%400==0)
{
if(day>0&&day<=29)
{
alert(year+"-"+month+"-"+day)
}
else
{
alert("输入有误")
} }
else
{
if(day>0&&day<=28)
{
alert(year+"-"+month+"-"+day)
}
else
{
alert("输入有误")
}
}
}
}
else
{
alert("输入有误")
}
}
else
{
alert("输入有误")
}
}
}
else
{
alert("输入有误")
}
}
else
{
alert("输入有误")
}
}
}
else
{
alert("输入有误")
}
}
else
{
alert("输入有误")
}
}
</script>
第二种(函数)
输入年月日看格式是否正确<br />
请输入年:<input type="number" )
}
}
</script>