写一个html摇奖页面
时间: 2023-12-18 08:03:47 浏览: 105
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>摇奖页面</title>
<style>
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f5f5f5;
}
#result {
font-size: 40px;
font-weight: bold;
margin-bottom: 50px;
color: #333;
}
button {
padding: 10px 20px;
font-size: 24px;
background-color: #008CBA;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<h1>摇奖页面</h1>
<div id="result"></div>
<button id="btn">开始摇奖</button>
</div>
<script>
const prizes = ['一等奖', '二等奖', '三等奖', '谢谢参与'];
const result = document.querySelector('#result');
const btn = document.querySelector('#btn');
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
btn.addEventListener('click', () => {
const index = getRandomInt(prizes.length);
result.textContent = prizes[index];
});
</script>
</body>
</html>
阅读全文