要创建一个抽奖活动,你可以使用HTML、CSS和JavaScript,以下是一个简单的示例:

1、创建一个HTML文件,添加以下内容:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF8">
<meta name="viewport" content="width=devicewidth, initialscale=1.0">
<title>抽奖活动</title>
<style>
/* 在这里添加CSS样式 */
</style>
</head>
<body>
<h1>欢迎参加抽奖活动!</h1>
<p>请在下面的表格中填写您的姓名和联系方式,然后点击“提交”按钮。</p>
<form id="participantForm">
<label for="name">姓名:</label>
<input type="text" id="name" required>
<br>
<label for="contact">联系方式:</label>
<input type="text" id="contact" required>
<br>
<button type="submit">提交</button>
</form>
<table id="participantsTable">
<thead>
<tr>
<th>姓名</th>
<th>联系方式</th>
</tr>
</thead>
<tbody>
<!参与者信息将在这里显示 >
</tbody>
</table>
<button id="drawButton" disabled>开始抽奖</button>
<div id="result"></div>
<script>
// 在这里添加JavaScript代码
</script>
</body>
</html>
2、接下来,添加CSS样式,在<style>标签内添加以下内容:
body {
fontfamily: Arial, sansserif;
}
h1 {
textalign: center;
}
form {
display: flex;
flexdirection: column;
alignitems: center;
marginbottom: 20px;
}
input {
margin: 5px;
}
button {
margintop: 10px;
}
table {
width: 100%;
bordercollapse: collapse;
}
th, td {
border: 1px solid black;
padding: 8px;
textalign: left;
}
th {
backgroundcolor: #f2f2f2;
}
3、添加JavaScript代码,在<script>标签内添加以下内容:
document.getElementById('participantForm').addEventListener('submit', function (event) {
event.preventDefault(); // 阻止表单默认提交行为
const name = document.getElementById('name').value;
const contact = document.getElementById('contact').value;
const table = document.getElementById('participantsTable').getElementsByTagName('tbody')[0];
const newRow = table.insertRow(table.rows.length);
const nameCell = newRow.insertCell(0);
const contactCell = newRow.insertCell(1);
nameCell.innerHTML = name;
contactCell.innerHTML = contact;
document.getElementById('name').value = '';
document.getElementById('contact').value = '';
document.getElementById('drawButton').disabled = false;
});
document.getElementById('drawButton').addEventListener('click', function () {
const participants = Array.from(document.getElementById('participantsTable').getElementsByTagName('tbody')[0].rows);
const randomIndex = Math.floor(Math.random() * participants.length);
const winner = participants[randomIndex];
document.getElementById('result').innerHTML = '恭喜 ' + winner.cells[0].innerHTML + ' 获得了奖品!';
document.getElementById('drawButton').disabled = true;
});
现在,你可以在浏览器中打开这个HTML文件,填写参与者信息并点击“开始抽奖”按钮,抽中的获奖者将在页面上显示。