判断年份是否为闰年及非法数据的处理

一、问题描述

   判断输入的年份是否为闰年

二、功能实现

  在输入栏中输入年份,点击确认按钮,若年份为闰年,则显示“您输入的年份是闰年”,如年份非闰年,则显示“您输入的年份不是闰年”

三、代码实现

<html>
<head>
<script type="text/javascript">
function test(){
var input1=document.getElementById('input1').value;

if input1%400==0
{
      windows.alert("您所输入的时间为闰年")
}
else if (input1%100!=0&&input1%4==0)
{
     windows.alert("您所输入的时间为闰年")
}
else
{
     windows.alert("您所输入的时间不是闰年")
}
}


</script>
</head>

<body>
<input type="text" id="input1" value ="输入1" /><br/>
<input type="button" onclick="test()" value="确定" />
</body>
</html>

   四、测试用例

测试用例 输出结果
1900 非闰年
2005   非闰年
3 非闰年
400 闰年
1804 闰年
2000 闰年
1987 非闰年
1400 非闰年
1576 闰年
原文地址:https://www.cnblogs.com/Lucasleiva/p/4396516.html