美文网首页
根据出生年份获取生肖

根据出生年份获取生肖

作者: 武汉前端阿杰1001 | 来源:发表于2022-04-22 10:29 被阅读0次

<!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>



相关文章

网友评论

      本文标题:根据出生年份获取生肖

      本文链接:https://www.haomeiwen.com/subject/uhngertx.html