HTML、JS、CSS、Vue、jQuery 联手:实现无重复组人员名单抽取!
以下是一个使用 HTML、JavaScript、CSS、Vue 和 jQuery 实现人员名单抽取,且同一个组中的人员不被重复抽中的示例代码: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>人员名单抽取</title> <style> /* 这里可以添加您的 CSS 样式 */ </style> </head> <body> <div id="app"> <button id="drawBtn">抽取</button> <ul id="resultList"></ul> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://unpkg.com/vue@3"></script> <script> // 定义人员数据 const people = [ { name: '张三', group: 'A' }, { name: '李四', group: 'A' }, { name: '王五', group: 'B' }, { name: '赵六', group: 'B' }, ]; // 定义 Vue 实例 const app = Vue.createApp({ data() { return { result: [], }; }, methods: { drawPeople() { // 用于存储已经抽取过的组 const drawnGroups = []; // 随机抽取人员 const randomPerson = people[Math.floor(Math.random() * people.length)]; // 如果该人员所在组未被抽取过,则添加到结果中 if (!drawnGroups.includes(randomPerson.group)) { this.result.push(randomPerson.name); drawnGroups.push(randomPerson.group); } }, }, }); // 挂载 Vue 实例 app.mount('#app'); // 给抽取按钮添加点击事件 $('#drawBtn').click(() => { app.drawPeople(); $('#resultList').empty(); app.result.forEach(person => { $('#resultList').append(`<li>${person}</li>`); }); }); </script> </body> </html> ``` 请问您对于这个抽取的逻辑有具体的数量要求吗?是否有特定的展示格式需求?抽取后是否需要进行其他操作? ######[AI写代码神器 | 575点数解答 | 2024-12-12 16:44:17]
- HTML+jQuery 实现列表元素悬停动画效果:代码详解与注意事项(字节豆包 | 475点数解答 | 2024-12-19 14:58:05)392
- HTML+jQuery:打造动态导航栏动画效果及注意事项(字节豆包 | 495点数解答 | 2024-12-19 14:58:06)336
- HTML+jQuery:打造带动态交互效果的商品展示页面(讯飞星火 | 497点数解答 | 2024-12-19 14:58:18)340
- HTML与jQuery结合:实现商品列表交互动画的首页代码解析(讯飞星火 | 497点数解答 | 2024-12-19 14:58:20)362
- "Debugging 'Cannot Read Properties of Null (reading \'userid\')' Error in Vue Components: Steps and Example"(讯飞星火 | 614点数解答 | 2024-11-28 14:31:57)291
- 锁屏页面代码优化:从内联样式到外部 CSS 的完美转变(字节豆包 | 2052点数解答 | 2025-05-31 12:45:02)239
- 锁屏页面代码优化:模块化、注释与兼容性全攻略(字节豆包 | 2110点数解答 | 2025-05-31 12:45:28)264
- 充值页面LayUI框架代码分析:问题、优化与逻辑要点(DeepSeek | 354点数解答 | 2025-05-05 02:54:04)208
- "Debugging 'Cannot Read Properties of Null (Reading 'userid')' Error: A Step-by-Step Guide"(讯飞星火 | 523点数解答 | 2024-11-28 14:32:05)268
- 解决 “Cannot read properties of null (reading 'userid')” 错误的代码修改方案(讯飞星火 | 516点数解答 | 2024-11-28 14:32:43)305
- 探秘这段 HTML 代码背后的网页奥秘(字节豆包 | 51点数解答 | 2024-12-09 20:31:23)366
- 帝王尬笑博客:技术、项目与生活点滴的精彩汇聚(GPT | 86点数解答 | 2024-11-16 02:59:47)306