index.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. }
  16. #container {
  17. width: auto;
  18. max-width: 1000px;
  19. margin: 50px auto;
  20. padding: 20px;
  21. background-color: #fff;
  22. box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
  23. border-radius: 5px;
  24. background-image: url('./back.png');
  25. background-size: cover;
  26. background-position: top center;
  27. background-repeat: no-repeat;
  28. }
  29. h1 {
  30. font-size: 24px;
  31. font-weight: bold;
  32. color: #0e0d0d;
  33. margin-bottom: 30px;
  34. }
  35. label {
  36. display: block;
  37. text-align: left;
  38. font-weight: bold;
  39. margin-bottom: 5px;
  40. margin-left: 10px;
  41. }
  42. textarea {
  43. height: 150px;
  44. }
  45. input {
  46. height: 30px;
  47. }
  48. textarea,
  49. input[type="text"] {
  50. width: 100%;
  51. /* padding: 10px; */
  52. border: 2px solid #f9ddcd8a;
  53. border-radius: 5px; /* 边框圆角 */
  54. resize: none;
  55. margin-left: -4px;
  56. margin-right: -4px;
  57. font-size: 16px;
  58. font-family: 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
  59. }
  60. input:focus,
  61. textarea:focus {
  62. outline: none;
  63. border: 3px solid #e053018a;
  64. }
  65. button {
  66. background-color: #3f51b5;
  67. color: #fff;
  68. border: none;
  69. padding: 10px 20px;
  70. font-size: 16px;
  71. font-weight: bold;
  72. border-radius: 3px;
  73. cursor: pointer;
  74. transition: background-color 0.3s ease;
  75. margin-top: 10px;
  76. }
  77. button:hover {
  78. background-color: #2f3d88;
  79. }
  80. .result-container {
  81. margin-top: 20px;
  82. }
  83. .result-container h2 {
  84. font-size: 18px;
  85. margin-bottom: 10px;
  86. color: #333;
  87. }
  88. .result-container p {
  89. font-size: 24px;
  90. font-weight: bold;
  91. color: #014dff;
  92. animation: blink 1.5s infinite;
  93. }
  94. @keyframes blink {
  95. 0% {
  96. opacity: 1;
  97. }
  98. 50% {
  99. opacity: 0;
  100. }
  101. 100% {
  102. opacity: 1;
  103. }
  104. }
  105. </style>
  106. </head>
  107. <body>
  108. <div id="container">
  109. <h1>申泽智能讲师文化活动抽奖环节</h1>
  110. <div>
  111. <label for="namesInput">请输入观众人名单:</label>
  112. <textarea
  113. id="namesInput"
  114. rows="4"
  115. placeholder="请使用英文逗号,分隔多个人名"
  116. ></textarea>
  117. </div>
  118. <div>
  119. <label for="excludedNamesInput"
  120. >请输入被排除的主持人和讲师:</label
  121. >
  122. <input
  123. type="text"
  124. id="excludedNamesInput"
  125. placeholder="请使用英文逗号,分隔多个人名"
  126. />
  127. </div>
  128. <button onclick="selectRandomName()">抽取随机人名</button>
  129. <div class="result-container">
  130. <h2>本次幸运观众是:</h2>
  131. <p id="randomName"></p>
  132. </div>
  133. </div>
  134. <script>
  135. function selectRandomName() {
  136. var namesInput = document.getElementById("namesInput").value;
  137. var excludedNamesInput =
  138. document.getElementById("excludedNamesInput").value;
  139. var namesArray = namesInput.split(",").map((name) => name.trim());
  140. var excludedNamesArray = excludedNamesInput.split(",").map((name) => name.trim());
  141. var filteredNames = filterNames(namesArray, excludedNamesArray);
  142. if (filteredNames.length === 0) {
  143. document.getElementById("randomName").innerHTML = "没有可抽取的人名";
  144. return;
  145. }
  146. // var randomIndex = Math.floor(Math.random() * filteredNames.length);
  147. // var randomName = filteredNames[randomIndex];
  148. // document.getElementById("randomName").innerHTML = randomName.trim();
  149. var luckyPerson =
  150. namesArray[Math.floor(Math.random() * namesArray.length)];
  151. while (excludedNamesArray.includes(luckyPerson)) {
  152. luckyPerson =
  153. namesArray[Math.floor(Math.random() * namesArray.length)];
  154. }
  155. document.getElementById("randomName").innerHTML =
  156. "恭喜 " + luckyPerson + " 中奖!";
  157. }
  158. function filterNames(namesArray, excludedNamesArray) {
  159. var filteredNames = [];
  160. for (var i = 0; i < namesArray.length; i++) {
  161. var name = namesArray[i].trim();
  162. if (name !== "" && !excludedNamesArray.includes(name)) {
  163. filteredNames.push(name);
  164. }
  165. }
  166. return filteredNames;
  167. }
  168. </script>
  169. </body>
  170. </html>