网站首页 > 技术文章 正文
复制以下内容至文本文件,修改文件后缀txt为html,即可使用。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>随机选择程序</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f0f0f0;
margin: 0;
}
#display {
font-size: 1.5em;
margin: 20px;
padding: 20px;
border: 2px solid #333;
border-radius: 10px;
background-color: #fff;
width: 80%;
text-align: center;
}
.red {
color: red;
}
.blue {
color: blue;
}
button {
font-size: 1.2em;
padding: 10px 20px;
margin: 10px;
border: none;
border-radius: 5px;
background-color: #007bff;
color: white;
cursor: pointer;
}
button:active {
background-color: #0056b3;
}
</style>
</head>
<body>
<div id="display">点击“开始”按钮,随机选择6个红色名单和1个蓝色名单</div>
<button id="startStopBtn">开始</button>
<script>
const redList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33];
const blueList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
let intervalId;
let isRunning = false;
// 随机选择函数
function getRandomItems(list, count) {
let shuffled = list.slice(); // 复制数组
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]; // 交换元素
}
return shuffled.slice(0, count); // 返回前count个元素
}
// 开始滚动
function startRolling() {
intervalId = setInterval(() => {
const randomRed = getRandomItems(redList, 6);
const randomBlue = getRandomItems(blueList, 1);
document.getElementById('display').innerHTML = `
<span class="red">红色名单:${randomRed.join(', ')}</span><br>
<span class="blue">蓝色名单:${randomBlue.join(', ')}</span>
`;
}, 100);
}
// 停止滚动
function stopRolling() {
clearInterval(intervalId);
}
// 按钮点击事件
document.getElementById('startStopBtn').addEventListener('click', () => {
if (isRunning) {
stopRolling();
document.getElementById('startStopBtn').textContent = '开始';
} else {
startRolling();
document.getElementById('startStopBtn').textContent = '停止';
}
isRunning = !isRunning;
});
</script>
</body>
</html>
猜你喜欢
- 2025-08-02 React Native 常见问题集合
- 2025-08-02 React-Native 样式指南
- 2025-08-02 SpringBoot集成DeepSeek
- 2025-08-02 课堂点名总尴尬?试试 DeepSeek,或能实现点名自由!(附教程)
- 2025-08-02 手把手带你完成OpenHarmony藏头诗App
- 2025-08-02 Web设计练习:制作人脸识别网页(基于TensorFlow的开源模型)
- 2025-08-02 CSS支持 if / else 了
- 2025-08-02 CSS粘性页脚布局:从Flexbox到Grid的现代实现指南
- 2025-08-02 CSS 2025新特性解析:容器查询与嵌套选择器的高级应用案例
- 2025-08-02 如何设置Flexbox项目之间的距离
- 08-02C|在一个结构体嵌套一个共用体实现一体多用
- 08-02C++中,常用的强制类型转换函数
- 08-02如何使用C语言编程实现一个推箱子游戏?技术核心和算法实现
- 08-02C++20 新特性(24):模板访问权限和typename的放宽
- 08-02C++零基础到工程实践
- 08-02[深度学习] Python人脸识别库face_recognition使用教程
- 08-02AI算法之怎么利用Python实现支持向量机SVM算法
- 08-02【机器学习】SVM支持向量机
- 1520℃桌面软件开发新体验!用 Blazor Hybrid 打造简洁高效的视频处理工具
- 623℃Dify工具使用全场景:dify-sandbox沙盒的原理(源码篇·第2期)
- 526℃MySQL service启动脚本浅析(r12笔记第59天)
- 492℃启用MySQL查询缓存(mysql8.0查询缓存)
- 491℃服务器异常重启,导致mysql启动失败,问题解决过程记录
- 479℃「赵强老师」MySQL的闪回(赵强iso是哪个大学毕业的)
- 460℃mysql服务怎么启动和关闭?(mysql服务怎么启动和关闭)
- 458℃MySQL server PID file could not be found!失败
- 最近发表
- 标签列表
-
- cmd/c (90)
- c++中::是什么意思 (84)
- 标签用于 (71)
- 主键只能有一个吗 (77)
- c#console.writeline不显示 (95)
- pythoncase语句 (88)
- es6includes (74)
- sqlset (76)
- windowsscripthost (69)
- apt-getinstall-y (100)
- node_modules怎么生成 (87)
- chromepost (71)
- flexdirection (73)
- c++int转char (80)
- static函数和普通函数 (76)
- el-date-picker开始日期早于结束日期 (70)
- c语言min函数头文件 (68)
- asynccallback (71)
- localstorage.removeitem (74)
- vector线程安全吗 (70)
- java (73)
- js数组插入 (83)
- mac安装java (72)
- 查看mysql是否启动 (70)
- 无效的列索引 (74)