生肖年(switch练习)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="text" id="a">
<input type="submit" id="b">
<div id="txt"></div>
<script>
var a=document.getElementById("a")
var b=document.getElementById("b")
var txt=document.getElementById("txt")

b.onclick=function(){
var m=a.value;
switch(m){
case "1992": txt.innerHTML="猴年";break;
case "1993": txt.innerHTML="鸡年";break;
case "1994": txt.innerHTML="狗年";break;
case "1995": txt.innerHTML="猪年";break;
case "1996": txt.innerHTML="鼠年";break;
case "1997": txt.innerHTML="牛年";break;
case "1998": txt.innerHTML="虎年";break;
case "1999": txt.innerHTML="兔年";break;
case "2000": txt.innerHTML="龙年";break;
case "2001": txt.innerHTML="蛇年";break;
case "2002": txt.innerHTML="马年";break;
case "2003": txt.innerHTML="羊年";break;
default: txt.innerHTML="error";
}
}
</script>
</body>
</html>

上一篇:深入浅出ES6(四):模板字符串


下一篇:Python文档