網(wǎng)站內(nèi)容管理系統(tǒng)建站企業(yè)網(wǎng)站
目錄
1、添加參與者
2、多次添加
3、點(diǎn)擊抽獎(jiǎng)
功能介紹:
使用方法:
完整代碼:
一個(gè)簡(jiǎn)單但功能強(qiáng)大的抽獎(jiǎng)系統(tǒng)的示例,用于在網(wǎng)頁(yè)上實(shí)現(xiàn)抽獎(jiǎng)。
1、添加參與者
2、多次添加
3、點(diǎn)擊抽獎(jiǎng)
功能介紹:
- 參與者添加:
- 用戶可以輸入?yún)⑴c者名字并點(diǎn)擊“添加參與者”按鈕將其加入列表。
- 添加的名字會(huì)顯示在頁(yè)面下方的列表中。
- 開始抽獎(jiǎng):
- 點(diǎn)擊“開始抽獎(jiǎng)”按鈕,系統(tǒng)會(huì)隨機(jī)從已添加的參與者中選出一個(gè)作為中獎(jiǎng)?wù)摺?/li>
- 抽獎(jiǎng)結(jié)果會(huì)顯示在頁(yè)面上。
- 動(dòng)態(tài)更新:
- 參與者列表動(dòng)態(tài)更新,顯示所有參與者的序號(hào)和名字。
使用方法:
- 打開瀏覽器,保存并運(yùn)行此HTML文件。
- 輸入?yún)⑴c者名字并點(diǎn)擊“添加參與者”。
- 點(diǎn)擊“開始抽獎(jiǎng)”,查看中獎(jiǎng)結(jié)果。
完整代碼:
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>抽獎(jiǎng)系統(tǒng)</title><style>body {font-family: Arial, sans-serif;background-color: #f4f4f9;margin: 0;padding: 0;display: flex;flex-direction: column;align-items: center;justify-content: center;height: 100vh;}.container {text-align: center;padding: 20px;background: white;border-radius: 10px;box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);}.title {font-size: 24px;font-weight: bold;margin-bottom: 20px;}.input-area {margin-bottom: 20px;}input, button {padding: 10px;margin: 5px;border-radius: 5px;border: 1px solid #ddd;font-size: 16px;}button {background: #007BFF;color: white;cursor: pointer;}button:hover {background: #0056b3;}.result {font-size: 18px;color: #28a745;margin-top: 20px;}</style>
</head>
<body><div class="container"><div class="title">高級(jí)抽獎(jiǎng)系統(tǒng)</div><div class="input-area"><input type="text" id="participant" placeholder="輸入?yún)⑴c者名字"><button onclick="addParticipant()">添加參與者</button></div><div><button onclick="startLottery()">開始抽獎(jiǎng)</button></div><div class="result" id="result"></div><ul id="participantsList"></ul></div><script>const participants = [];function addParticipant() {const input = document.getElementById('participant');const name = input.value.trim();if (name) {participants.push(name);updateParticipantsList();input.value = '';} else {alert('請(qǐng)輸入有效的名字!');}}function updateParticipantsList() {const list = document.getElementById('participantsList');list.innerHTML = '';participants.forEach((name, index) => {const li = document.createElement('li');li.textContent = `${index + 1}. ${name}`;list.appendChild(li);});}function startLottery() {if (participants.length === 0) {alert('請(qǐng)先添加參與者!');return;}const winnerIndex = Math.floor(Math.random() * participants.length);const winner = participants[winnerIndex];document.getElementById('result').textContent = `恭喜 ${winner} 中獎(jiǎng)!`;}</script>
</body>
</html>
?如果需要更多高級(jí)功能,例如獎(jiǎng)品設(shè)置、多輪抽獎(jiǎng)等,可以進(jìn)一步擴(kuò)展邏輯!
嗨,我是命運(yùn)之光。如果你覺得我的分享有價(jià)值,不妨通過以下方式表達(dá)你的支持:👍 點(diǎn)贊來表達(dá)你的喜愛,📁 關(guān)注以獲取我的最新消息,💬 評(píng)論與我交流你的見解。我會(huì)繼續(xù)努力,為你帶來更多精彩和實(shí)用的內(nèi)容。
點(diǎn)擊這里👉 ,獲取最新動(dòng)態(tài),?? 讓信息傳遞更加迅速。