05-随机抽奖素材

<!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>
  <style>
    .wrapper {
      width: 840px;
      height: 420px;
      background: url(./images/bg01.jpg) no-repeat center / cover;
      padding: 100px 250px;
      box-sizing: border-box;
    }
  </style>
</head>

<body>
  <div class="wrapper">
    <strong>传智教育年会抽奖</strong>
    <h1>一等奖:<span id="one">???</span></h1>
    <h3>二等奖:<span id="two">???</span></h3>
    <h5>三等奖:<span id="three">???</span></h5>
  </div>
  <script>
    // 1.声明数组
    const personArr = ['周杰伦', '刘德华', '周星驰', 'Pink老师', '张学友']
    // 2.先做一等奖
    // 2.1 随机数
    const random = Math.floor(Math.random() * personArr.length)
    // console.log(personArr[random])
    // 2.2 获取one元素
    const one = document.querySelector('#one')
    // 2.3 把名字给one
    one.innerHTML = personArr[random]
    // 2.4 删除这个名字
    personArr.splice(random, 1)

    // 3.做二等奖
    // 3.1 随机数
    const random2 = Math.floor(Math.random() * personArr.length)
    // console.log(personArr[random])
    // 3.2 获取two元素
    const two = document.querySelector('#two')
    // 3.3 把名字给two
    two.innerHTML = personArr[random2]
    // 3.4 删除这个名字
    personArr.splice(random2, 1)

    // 4.做三等奖
    // 4.1 随机数
    const random3 = Math.floor(Math.random() * personArr.length)
    // console.log(personArr[random])
    // 4.2 获取three元素
    const three = document.querySelector('#three')
    // 4.3 把名字给three
    three.innerHTML = personArr[random3]
    // 4.4 删除这个名字
    personArr.splice(random3, 1)
  </script>
</body>

</html>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值