study/html/判断是否是闰年.html
2022-08-04 12:30:02 +08:00

31 lines
815 B
HTML

<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="" />
<title>判断是否是闰年</title>
</head>
<body>
<h1>判断是否是闰年</h1>
<h2>作者:赵海洋</h2>
<input type="text" id="year" placeholder="输入年份" />
<button onclick="check()">运行</button>
<script>
// 判断是否是闰年
function isleap(y) {
return (y % 100 !== 0 && y % 4 === 0) || y % 400 === 0;
}
function check() {
if (isleap(year.value)) {
alert("是闰年");
} else {
alert("不是闰年");
}
}
</script>
</body>
</html>