index.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>申泽智能科技</title>
  7. <link rel="icon" type="image/x-icon" href="favicon.ico" />
  8. <style>
  9. body {
  10. text-align: center;
  11. background-color: #f2f2f2;
  12. font-family: Arial, sans-serif;
  13. margin: 0;
  14. padding: 0;
  15. overflow: hidden;
  16. }
  17. #container {
  18. width: auto;
  19. height: 585px;
  20. max-width: 1200px;
  21. margin: 50px auto;
  22. padding: 20px;
  23. /* background-color: #f2d1c3; */
  24. box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
  25. border-radius: 5px;
  26. background-image: url("./back.jpg");
  27. background-size: cover;
  28. background-position: top center;
  29. background-repeat: no-repeat;
  30. border-radius: 8px; /* 边框圆角 */
  31. }
  32. h1 {
  33. font-size: 30px;
  34. font-weight: bold;
  35. color: #fcfcfc;
  36. margin-bottom: 30px;
  37. }
  38. label {
  39. display: block;
  40. text-align: left;
  41. font-weight: bold;
  42. margin-bottom: 5px;
  43. margin-left: 10px;
  44. }
  45. textarea {
  46. height: 150px;
  47. }
  48. input {
  49. height: 30px;
  50. }
  51. textarea,
  52. input[type="text"] {
  53. width: 100%;
  54. /* padding: 10px; */
  55. border: 3px solid #94e07fa8;
  56. border-radius: 5px; /* 边框圆角 */
  57. resize: none;
  58. margin-left: -4px;
  59. margin-right: -4px;
  60. font-size: 24px;
  61. font-style: bold;
  62. font-family: "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
  63. }
  64. input:focus,
  65. textarea:focus {
  66. outline: none;
  67. border: 3px solid #e053018a;
  68. }
  69. button {
  70. background-color: #e79b54;
  71. color: #fff;
  72. border: none;
  73. padding: 10px 20px;
  74. font-size: 16px;
  75. font-weight: bold;
  76. border-radius: 3px;
  77. cursor: pointer;
  78. transition: background-color 0.3s ease;
  79. margin-top: 10px;
  80. }
  81. button:hover {
  82. background-color: #e8750a;
  83. }
  84. .result-container {
  85. margin-top: 20px;
  86. }
  87. .result-container h2 {
  88. font-size: 18px;
  89. margin-bottom: 10px;
  90. color: #333;
  91. }
  92. .result-container p {
  93. font-size: 28px;
  94. font-weight: bold;
  95. color: #cf3400;
  96. animation: blink 1.5s infinite;
  97. }
  98. @keyframes blink {
  99. 0% {
  100. opacity: 1;
  101. }
  102. 50% {
  103. opacity: 0;
  104. }
  105. 100% {
  106. opacity: 1;
  107. }
  108. }
  109. .custom-select {
  110. position: relative;
  111. width: 130px;
  112. margin: 5px auto;
  113. }
  114. .custom-select select {
  115. width: 100%;
  116. padding: 8px;
  117. border: 2px solid #a77fe0a8;
  118. border-radius: 5px; /* 边框圆角 */
  119. }
  120. .pull-right {
  121. float: right;
  122. }
  123. </style>
  124. </head>
  125. <body>
  126. <div id="container">
  127. <h1>申泽智能讲师文化活动抽奖环节</h1>
  128. <div class="custom-select pull-right">
  129. <select name="selectSection" id="departmentSelect">
  130. <option value="">选择部门</option>
  131. <option value="RD">研发&综合中心</option>
  132. <option value="PD">生产部</option>
  133. <option value="MD">营销部</option>
  134. </select>
  135. </div>
  136. <br />
  137. <div>
  138. <label for="namesInput">请输入观众人名单:</label>
  139. <textarea
  140. id="namesInput"
  141. rows="4"
  142. placeholder="请使用逗号分隔多个人名"
  143. ></textarea>
  144. </div>
  145. <div>
  146. <label for="excludedNamesInput">请输入被排除的主持人和讲师:</label>
  147. <input
  148. type="text"
  149. id="excludedNamesInput"
  150. placeholder="请使用逗号分隔多个人名"
  151. />
  152. </div>
  153. <br />
  154. <br />
  155. <button id="submitBtn" onclick="selectRandomName()">抽取随机人名</button>
  156. <div class="result-container">
  157. <h2>本次幸运观众是:</h2>
  158. <p id="randomName"></p>
  159. </div>
  160. </div>
  161. <script>
  162. // 只允许输入中英文字符,空格
  163. var inputPattern = /^[\u4e00-\u9fa5a-zA-Z\s,,]+$|^$/;
  164. document
  165. .getElementById("submitBtn")
  166. .addEventListener("click", function () {
  167. // 获取用户输入的人名单
  168. var namesInput = document.getElementById("namesInput").value;
  169. var excludedNamesInput =
  170. document.getElementById("excludedNamesInput").value;
  171. if (
  172. !inputPattern.test(namesInput) ||
  173. !inputPattern.test(excludedNamesInput)
  174. ) {
  175. alert("非法字符,请重新输入!");
  176. return;
  177. }
  178. // 将中文逗号全局替换成英文逗号
  179. namesInput = namesInput.replace(/,/g, ",");
  180. excludedNamesInput = excludedNamesInput.replace(/,/g, ",");
  181. var namesArray = namesInput.split(",").map((name) => name.trim());
  182. var excludedNamesArray = excludedNamesInput
  183. .split(",")
  184. .map((name) => name.trim());
  185. selectRandomName(namesArray, excludedNamesArray);
  186. });
  187. document
  188. .getElementById("departmentSelect")
  189. .addEventListener("change", function () {
  190. var selectDepartment = this.value;
  191. var namesInput = document.getElementById("namesInput");
  192. if (selectDepartment === "RD") {
  193. namesInput.value =
  194. "张凤兰, 王巧贤, 阮珊珊, 谢焕婷, 李婕妤, 李广, 高旭坤, 刘云, 邓远锋, 吴宗澍, 曾文龙, 黄彦, 刘银华, 肖夜华, 严成发, 文孔燊, 洪序滨, 江锦文, 张乐瑶, 张镜明, 陈智雄, 陈珍旭, 王莞琳, 王和富, 王则钰, 王杰, 蔡文怡";
  195. } else if (selectDepartment === "PD") {
  196. namesInput.value = "张三, 李四, 王五";
  197. } else if (selectDepartment === "MD") {
  198. namesInput.value = "a, b, c";
  199. }
  200. });
  201. function selectRandomName(namesArray, excludedNamesArray) {
  202. var filteredNames = filterNames(namesArray, excludedNamesArray);
  203. if (filteredNames.length === 0) {
  204. document.getElementById("randomName").innerHTML = "没有可抽取的人名";
  205. return;
  206. }
  207. var interval = setInterval(function () {
  208. var randomIndex = Math.floor(Math.random() * filteredNames.length);
  209. document.getElementById("randomName").innerHTML =
  210. "是(¬‿¬): " + filteredNames[randomIndex] + " ?";
  211. }, 400);
  212. setTimeout(() => {
  213. clearInterval(interval);
  214. var luckyPerson =
  215. namesArray[Math.floor(Math.random() * namesArray.length)];
  216. while (excludedNamesArray.includes(luckyPerson)) {
  217. luckyPerson =
  218. namesArray[Math.floor(Math.random() * namesArray.length)];
  219. }
  220. document.getElementById("randomName").innerHTML =
  221. "恭喜 " + luckyPerson + " 中奖o(^▽^)o";
  222. }, 4000);
  223. }
  224. function filterNames(namesArray, excludedNamesArray) {
  225. var filteredNames = [];
  226. for (var i = 0; i < namesArray.length; i++) {
  227. var name = namesArray[i].trim();
  228. if (name !== "" && !excludedNamesArray.includes(name)) {
  229. filteredNames.push(name);
  230. }
  231. }
  232. return filteredNames;
  233. }
  234. </script>
  235. </body>
  236. </html>