<!DOCTYPE html>
<html lang="en">
<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">
<title>Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<fieldset>
<legend>根据出生年份计算生肖</legend>
<p align="center">请输入<span style="color:red ;font-weight: 600;">2122班</span>的出生年份:
<input name="txtYear" type="text" id="txtYear" size="12" />
<input name="btnShow" type="button" id="btnShow" value="显示生肖" onclick="showShengxiao();" />
</p>
<p id="Shengxiao" align="center"> </p>
</fieldset>
</form>
<script>
var year = Number(document.getElementById("txtYear").innerHTML);
function showShengxiao() {
if (isNaN(year)) {
alert("请输入正确年份");
} else {
switch (year % 12) {
case 0:
document.getElementById("Shengxiao").innerHTML = "猴";
break;
case 1:
document.getElementById("Shengxiao").innerHTML = "鸡";
break;
case 2:
document.getElementById("Shengxiao").innerHTML = "狗";
break;
case 3:
document.getElementById("Shengxiao").innerHTML = "猪";
break;
case 4:
document.getElementById("Shengxiao").innerHTML = "鼠";
break;
case 5:
document.getElementById("Shengxiao").innerHTML = "牛";
break;
case 6:
document.getElementById("Shengxiao").innerHTML = "虎";
break;
case 7:
document.getElementById("Shengxiao").innerHTML = "兔";
break;
case 8:
document.getElementById("Shengxiao").innerHTML = "龙";
break;
case 9:
document.getElementById("Shengxiao").innerHTML = "蛇";
break;
case 10:
document.getElementById("Shengxiao").innerHTML = "马";
break;
case 11:
document.getElementById("Shengxiao").innerHTML = "羊";
break;
}
}
}
</script>
</body>
</html>
请问为什么我每次输入不同的数字,出来的是同一个·生肖,而且系统也不会判断是否正确