<!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>小学编程题:根据出生年份获取生肖</title>
</head>
<body>
<input type="text" name="" id="input" />
<button id="btn">搜索</button>
<script>
var animals = [
'猴',
'鸡',
'狗',
'猪',
'鼠',
'牛',
'虎',
'兔',
'龙',
'蛇',
'马',
'羊',
]
let btn = document.getElementById('btn')
btn.onclick = function (params) {
let input = document.getElementById('input').value
let animal = animals[input % 12]
console.log(animal)
}
</script>
</body>
</html>
网友评论