Files

237 lines
6.7 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<link rel="icon" href="../../favicon.svg">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>随机抽取器</title>
<link rel="canonical" href="https://www.htmls.dev/tools/random-picker/app.html">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #06b6d4 0%, #06b6d4 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1000px;
margin: 0 auto;
}
.header {
text-align: center;
color: white;
margin-bottom: 30px;
}
.header h1 {
font-size: 2.5rem;
margin-bottom: 10px;
}
.card {
background: rgba(255, 255, 255, 0.95);
border-radius: 20px;
padding: 30px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.form-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
gap: 20px;
margin-bottom: 20px;
}
.form-field {
display: flex;
flex-direction: column;
gap: 8px;
}
.form-field label {
font-weight: 600;
color: #333;
}
.form-field input,
.form-field textarea,
.form-field select {
padding: 10px 12px;
border-radius: 10px;
border: 1px solid #d0d7de;
font-size: 14px;
font-family: inherit;
}
.checkbox-group {
display: flex;
flex-direction: column;
gap: 6px;
font-size: 14px;
}
.form-actions {
display: flex;
gap: 10px;
flex-wrap: wrap;
margin-bottom: 20px;
}
.btn {
padding: 12px 24px;
border: none;
border-radius: 10px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
background: linear-gradient(135deg, #06b6d4 0%, #06b6d4 100%);
color: white;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}
.btn-secondary {
background: #6c757d;
}
.output-box {
display: flex;
flex-direction: column;
gap: 8px;
}
.output-box label {
font-weight: 600;
color: #333;
}
.output-box textarea {
padding: 12px;
border-radius: 10px;
border: 1px solid #d0d7de;
font-family: 'Courier New', monospace;
font-size: 14px;
resize: none;
}
.tool-doc-link,
.tool-home-link {
position: fixed;
top: 16px;
padding: 6px 12px;
border-radius: 999px;
font-size: 12px;
font-weight: 600;
color: #0f172a;
background: rgba(255, 255, 255, 0.9);
border: 1px solid rgba(15, 23, 42, 0.12);
text-decoration: none;
letter-spacing: 0.02em;
z-index: 9999;
box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}
.tool-doc-link {
right: 16px;
}
.tool-home-link {
right: 74px;
}
.tool-doc-link:hover,
.tool-home-link:hover {
background: rgba(255, 255, 255, 1);
border-color: rgba(15, 23, 42, 0.2);
transform: translateY(-1px);
}
</style>
</head>
<body>
<a class="tool-home-link" href="../../index.html">首页</a>
<a class="tool-doc-link" href="index.html">说明</a>
<div class="container">
<div class="header">
<h1>随机抽取器</h1>
<p>从列表中随机抽取项目</p>
</div>
<div class="card">
<div class="form-grid">
<div class="form-field">
<label for="picker-items">列表(每行一个)</label>
<textarea id="picker-items" rows="6" placeholder="Alice
Bob
Charlie"></textarea>
</div>
<div class="form-field">
<label for="picker-count">抽取数量</label>
<input id="picker-count" type="number" value="1" min="1" max="50">
</div>
<div class="form-field">
<label><input type="checkbox" id="picker-unique" checked> 不重复</label>
</div>
</div>
<div class="form-actions">
<button class="btn" onclick="pickRandomItems()">开始抽取</button>
<button class="btn btn-secondary" onclick="clearOutput()">清空输出</button>
</div>
<div class="output-box">
<label>抽取结果</label>
<textarea id="picker-output" rows="4" readonly></textarea>
</div>
</div>
</div>
<script>
function pickRandomItems() {
const items = document.getElementById('picker-items').value.split(/\r?\n/).filter(Boolean);
const count = parseInt(document.getElementById('picker-count').value, 10) || 1;
const unique = document.getElementById('picker-unique').checked;
if (items.length === 0) {
alert('请先输入列表');
return;
}
if (count < 1) {
alert('抽取数量必须大于0');
return;
}
if (unique && count > items.length) {
alert(`列表中只有 ${items.length} 项,无法抽取 ${count} 个不重复项目`);
return;
}
const pool = [...items];
const result = [];
for (let i = 0; i < count && pool.length > 0; i++) {
const index = Math.floor(Math.random() * pool.length);
result.push(pool[index]);
if (unique) pool.splice(index, 1);
}
document.getElementById('picker-output').value = result.join('\n');
}
function clearOutput() {
document.getElementById('picker-output').value = '';
}
</script>
<script src="../../assets/clicks.js" defer></script>
</body>
</html>