87,996
社区成员




<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>判断是否闰年</title>
</head>
<body>
年份:<input type="text" name="year" id="year" value="0" style="width:80px;" />
<input type="button" name="name" value="判断" onclick="test(document.getElementById('year').value);" />
</body>
</html>
<script>
function test(y) {
y = parseInt(y, 10);
if (isNaN(y) || y < 0) {
alert('输入的年份不正确');
return;
}
var isLeapYear = ((y % 4 === 0) && (y % 100 !== 0)) || (y % 400 === 0);
alert('输入的年份是否闰年:' + isLeapYear);
}
</script>