HTML點名器代碼
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>HTML點名器</title> <style> body { background-color: #F5F5F5; font-family: Arial, sans-serif; } h1 { text-align: center; } label { font-size: 20px; display: block; margin-top: 20px; } input[type="text"] { font-size: 20px; padding: 10px; border: none; border-radius: 5px; box-shadow: 1px 1px 5px #D3D3D3; width: 100%; } input[type="button"] { font-size: 20px; padding: 10px 20px; border: none; border-radius: 5px; background-color: #4CAF50; color: white; cursor: pointer; margin-top: 20px; } input[type="button"]:hover { background-color: #2E8B57; } #result { font-size: 30px; font-weight: bold; padding-top: 50px; text-align: center; } </style> </head> <body> <h1>HTML點名器</h1> <label>請輸入學生姓名,多個學生用逗號隔開</label> <input type="text" id="students" placeholder="例如:張三,李四,王五" autofocus> <input type="button" value="開始點名" onclick="randomName()"> <div id="result"></div> <script> function randomName() { var students = document.getElementById("students").value; var arrNames = students.split(","); var randomIndex = Math.floor(Math.random() * arrNames.length); var selectedName = arrNames[randomIndex].trim(); var result = document.getElementById("result"); result.innerHTML = "點名結果:" + selectedName; } </script> </body> </html>