123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>申泽智能科技</title>
- <link rel="icon" type="image/x-icon" href="favicon.ico" />
- <style>
- body {
- text-align: center;
- background-color: #f2f2f2;
- font-family: Arial, sans-serif;
- margin: 0;
- padding: 0;
- }
- #container {
- width: auto;
- max-width: 1000px;
- margin: 50px auto;
- padding: 20px;
- background-color: #fff;
- box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
- border-radius: 5px;
- background-image: url("./back.png");
- background-size: cover;
- background-position: top center;
- background-repeat: no-repeat;
- }
- h1 {
- font-size: 24px;
- font-weight: bold;
- color: #0e0d0d;
- margin-bottom: 30px;
- }
- label {
- display: block;
- text-align: left;
- font-weight: bold;
- margin-bottom: 5px;
- margin-left: 10px;
- }
- textarea {
- height: 150px;
- }
- input {
- height: 30px;
- }
- textarea,
- input[type="text"] {
- width: 100%;
- /* padding: 10px; */
- border: 2px solid #f9ddcd8a;
- border-radius: 5px; /* 边框圆角 */
- resize: none;
- margin-left: -4px;
- margin-right: -4px;
- font-size: 16px;
- font-family: "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
- }
- input:focus,
- textarea:focus {
- outline: none;
- border: 3px solid #e053018a;
- }
- button {
- background-color: #545be7;
- color: #fff;
- border: none;
- padding: 10px 20px;
- font-size: 16px;
- font-weight: bold;
- border-radius: 3px;
- cursor: pointer;
- transition: background-color 0.3s ease;
- margin-top: 10px;
- }
- button:hover {
- background-color: #2630e3;
- }
- .result-container {
- margin-top: 20px;
- }
- .result-container h2 {
- font-size: 18px;
- margin-bottom: 10px;
- color: #333;
- }
- .result-container p {
- font-size: 24px;
- font-weight: bold;
- color: #014dff;
- animation: blink 1.5s infinite;
- }
- @keyframes blink {
- 0% {
- opacity: 1;
- }
- 50% {
- opacity: 0;
- }
- 100% {
- opacity: 1;
- }
- }
- .custom-select {
- position: relative;
- width: 130px;
- margin: 5px auto;
- }
- .custom-select select {
- width: 100%;
- padding: 8px;
- border: 2px solid #94e07fa8;
- border-radius: 5px; /* 边框圆角 */
- }
- .pull-right {
- float: right;
- }
- </style>
- </head>
- <body>
- <div id="container">
- <h1>申泽智能讲师文化活动抽奖环节</h1>
- <div class="custom-select pull-right">
- <select name="selectSection" id="departmentSelect">
- <option value="">选择部门</option>
- <option value="RD">研发&综合中心</option>
- <option value="PD">生产部</option>
- <option value="MD">营销部</option>
- </select>
- </div>
- <br />
- <div>
- <label for="namesInput">请输入观众人名单:</label>
- <textarea
- id="namesInput"
- rows="4"
- placeholder="请使用逗号分隔多个人名"
- ></textarea>
- </div>
- <div>
- <label for="excludedNamesInput">请输入被排除的主持人和讲师:</label>
- <input
- type="text"
- id="excludedNamesInput"
- placeholder="请使用逗号分隔多个人名"
- />
- </div>
- <br />
- <br />
- <button id="submitBtn" onclick="selectRandomName()">抽取随机人名</button>
- <div class="result-container">
- <h2>本次幸运观众是:</h2>
- <p id="randomName"></p>
- </div>
- </div>
- <script>
- // 只允许输入中英文字符,空格
- var inputPattern = /^[\u4e00-\u9fa5a-zA-Z\s,,]+$|^$/;
- document
- .getElementById("submitBtn")
- .addEventListener("click", function () {
- // 获取用户输入的人名单
- var namesInput = document.getElementById("namesInput").value;
- var excludedNamesInput =
- document.getElementById("excludedNamesInput").value;
- if (
- !inputPattern.test(namesInput) ||
- !inputPattern.test(excludedNamesInput)
- ) {
- alert("非法字符,请重新输入!");
- return;
- }
- // 将中文逗号全局替换成英文逗号
- namesInput = namesInput.replace(/,/g, ",");
- excludedNamesInput = excludedNamesInput.replace(/,/g, ",");
- var namesArray = namesInput.split(",").map((name) => name.trim());
- var excludedNamesArray = excludedNamesInput
- .split(",")
- .map((name) => name.trim());
- selectRandomName(namesArray, excludedNamesArray);
- });
- document
- .getElementById("departmentSelect")
- .addEventListener("change", function () {
- var selectDepartment = this.value;
- var namesInput = document.getElementById("namesInput");
- if (selectDepartment === "RD") {
- namesInput.value = "张凤兰, 王巧贤, 阮珊珊, 谢焕婷, 李婕妤, 李广, 高旭坤, 刘云, 邓远锋, 吴宗澍, 曾文龙, 黄彦, 刘银华, 肖夜华, 严成发, 文孔燊, 洪序滨, 江锦文, 张乐瑶, 张镜明, 陈智雄, 陈珍旭, 王莞琳, 王和富, 王则钰, 王杰";
- } else if (selectDepartment === "PD") {
- namesInput.value = "张三, 李四, 王五";
- } else if (selectDepartment === "MD") {
- namesInput.value = "a, b, c";
- }
- });
- function selectRandomName(namesArray, excludedNamesArray) {
- var filteredNames = filterNames(namesArray, excludedNamesArray);
- if (filteredNames.length === 0) {
- document.getElementById("randomName").innerHTML = "没有可抽取的人名";
- return;
- }
- var luckyPerson =
- namesArray[Math.floor(Math.random() * namesArray.length)];
- while (excludedNamesArray.includes(luckyPerson)) {
- luckyPerson =
- namesArray[Math.floor(Math.random() * namesArray.length)];
- }
- document.getElementById("randomName").innerHTML =
- "恭喜 " + luckyPerson + " 中奖!";
- }
- function filterNames(namesArray, excludedNamesArray) {
- var filteredNames = [];
- for (var i = 0; i < namesArray.length; i++) {
- var name = namesArray[i].trim();
- if (name !== "" && !excludedNamesArray.includes(name)) {
- filteredNames.push(name);
- }
- }
- return filteredNames;
- }
- </script>
- </body>
- </html>
|