study/练习/练习1.html

25 lines
782 B
HTML
Raw Permalink Normal View History

2022-12-18 07:56:32 +00:00
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" ,content="width=device-width, initial-scale=1.0" />
<link rel="shortcut icon" href="data:" type="image/x-icon" />
<title>判断闰年</title>
</head>
<body>
<input type="text" id="year" placeholder="输入按回车" />
<p id="result"></p>
<script>
document.addEventListener('keyup', (e) => {
if (e.key == 'Enter' && year.value.match(/^[1-9]\d*/)) {
const Y = Number(year.value)
const N = Y % 400 == 0 || Y % 100 && Y % 4 == 0 ? '' : '不'
result.innerText = `${Y}是${N}闰年`
year.value = '' //把格子清空。
year.focus() // 把光标移格子里。
}
})
</script>
</body>
</html>