<!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>
05-随机抽奖素材
最新推荐文章于 2024-07-13 11:50:40 发布