生成考号的需要,弄一个网页来解决。
<!DOCTYPE html>
<html lang="en">
<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;
background-color: #f0f4f8;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
padding-top: 50px; /* 添加此行 */
}
h1 {
color: #333;
}
textarea {
width: 100%;
max-width: 600px;
height: 350px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 20px;
font-size: 16px;
}
button {
padding: 10px 20px;
margin: 5px;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
background-color: #007bff;
color: #fff;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
table {
width: 100%;
max-width: 800px;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
border: 1px solid #ccc;
padding: 10px;
text-align: center;
}
th {
background-color: #007bff;
color: #fff;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
@media (max-width: 600px) {
textarea {
height: 150px;
}
button {
width: 100%;
margin: 5px 0;
}
table, th, td {
font-size: 14px;
}
}
footer {
margin-top: 20px;
font-size: 14px;
color: #666;
}
</style>
</head>
<body>
<h1>考号生成器</h1>
<textarea id="examInput" placeholder="1 30 2 30 3 30 4 50 5 50"></textarea><br>
<span><button onclick="generateExamSeats()">生成考号</button>
<button onclick="clearExamSeatsData()">清除数据</button></span>
<table>
<thead>
<tr>
<th>考场号</th>
<th>座位号</th>
<th>考号</th>
</tr>
</thead>
<tbody id="examData">
<!-- Data will be inserted here -->
</tbody>
</table>
<div id="toast" style="display: none; position: fixed; top: 20px; left: 50%; transform: translateX(-50%); background-color: #666; color: #fff; padding: 10px 20px; border-radius: 5px; font-size: 14px; z-index: 1000;">
</div>
<footer>© <span id="year"></span> <a href="https://mj.morecale.com/">莫卡乐</a></footer>
<script>
function generateExamSeats() {
const input = document.getElementById('examInput').value.trim();
if (!input) {
alert("请输入考场数据,每行格式为:考场号 考生数(例如:1 30)");
return;
}
const lines = input.split('\n');
const exams = [];
for (let line of lines) {
const parts = line.trim().split(/\s+/);
if (parts.length !== 2 || isNaN(parseInt(parts[0], 10)) || isNaN(parseInt(parts[1], 10))) {
alert(`无效输入: '${line}'。请确保每行格式正确,如 '1 30'。`);
return;
}
exams.push({
examNumber: parseInt(parts[0], 10),
examCount: parseInt(parts[1], 10)
});
}
const table = document.getElementById('examData');
table.innerHTML = ''; // 清空当前数据
exams.forEach(exam => {
const examNumber = exam.examNumber.toString().padStart(2, '0');
for (let i = 1; i <= exam.examCount; i++) {
const seatNumber = i.toString().padStart(2, '0');
const combined = examNumber + seatNumber;
const row = table.insertRow();
row.insertCell(0).textContent = examNumber;
row.insertCell(1).textContent = seatNumber;
row.insertCell(2).textContent = combined;
}
});
// alert("生成考号成功!");
showToast("生成考号成功!", 2000); // 显示2秒
}
function showToast(message, duration) {
var toast = document.getElementById('toast');
toast.textContent = message;
toast.style.display = 'block';
setTimeout(function() {
toast.style.display = 'none';
}, duration);
}
function clearExamSeatsData() {
const table = document.getElementById('examData');
table.innerHTML = ''; // Clear all data
}
// Function to set current year in footer
function setCurrentYear() {
const yearSpan = document.getElementById('year');
yearSpan.textContent = new Date().getFullYear();
}
// Set the current year when the page loads
window.onload = setCurrentYear;
</script>
</body>
</html>
在线使用:如果有能帮到你,就来这里点个赞吧!
https://chat.morecale.com/exam.html
今天突然来用的时候,发现需要生成一个3位的座位号,修改了一下,更方便一些了。
<!DOCTYPE html>
<html lang="en">
<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;
background-color: #f0f4f8;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
padding-top: 50px;
}
h1 {
color: #333;
}
textarea {
width: 100%;
max-width: 600px;
height: 350px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 20px;
font-size: 16px;
}
button {
padding: 10px 20px;
margin: 5px;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
background-color: #007bff;
color: #fff;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
table {
width: 100%;
max-width: 800px;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
border: 1px solid #ccc;
padding: 10px;
text-align: center;
}
th {
background-color: #007bff;
color: #fff;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
@media (max-width: 600px) {
textarea {
height: 150px;
}
button {
width: 100%;
margin: 5px 0;
}
table, th, td {
font-size: 14px;
}
}
footer {
margin-top: 20px;
font-size: 14px;
color: #666;
}
</style>
</head>
<body>
<h1>考号生成器</h1>
<textarea id="examInput" placeholder="1 30 2 30 3 30 4 50 5 50"></textarea><br>
<label><input type="checkbox" id="threeDigitOption"> 三位考号</label>
<label><input type="checkbox" id="yearOption"> 增加年份</label><br>
<span>
<button onclick="generateExamSeats()">生成考号</button>
<button onclick="clearExamSeatsData()">清除数据</button>
<button id="exportButton" onclick="exportToExcel()" style="display: none;">导出考号</button>
</span>
<table>
<thead>
<tr>
<th>考场号</th>
<th>座位号</th>
<th>考号</th>
</tr>
</thead>
<tbody id="examData">
<!-- Data will be inserted here -->
</tbody>
</table>
<div id="toast" style="display: none; position: fixed; top: 20px; left: 50%; transform: translateX(-50%); background-color: #666; color: #fff; padding: 10px 20px; border-radius: 5px; font-size: 14px; z-index: 1000;">
</div>
<footer>© <span id="year"></span> <a href="https://mj.morecale.com/">莫卡乐</a></footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
<script>
function generateExamSeats() {
const input = document.getElementById('examInput').value.trim();
const threeDigitOption = document.getElementById('threeDigitOption').checked;
const yearOption = document.getElementById('yearOption').checked;
const year = new Date().getFullYear().toString();
if (!input) {
alert("请输入考场数据,每行格式为:考场号 考生数(例如:1 30)");
return;
}
const lines = input.split('\n');
const exams = [];
for (let line of lines) {
const parts = line.trim().split(/\s+/);
if (parts.length !== 2 || isNaN(parseInt(parts[0], 10)) || isNaN(parseInt(parts[1], 10))) {
alert(`无效输入: '${line}'。请确保每行格式正确,如 '1 30'。`);
return;
}
exams.push({
examNumber: parseInt(parts[0], 10),
examCount: parseInt(parts[1], 10)
});
}
const table = document.getElementById('examData');
table.innerHTML = ''; // 清空当前数据
exams.forEach(exam => {
const examNumber = exam.examNumber.toString().padStart(2, '0');
for (let i = 1; i <= exam.examCount; i++) {
const seatNumber = i.toString().padStart(threeDigitOption ? 3 : 2, '0');
const combined = (yearOption ? year : '') + examNumber + seatNumber;
const row = table.insertRow();
row.insertCell(0).textContent = examNumber;
row.insertCell(1).textContent = seatNumber;
row.insertCell(2).textContent = combined;
}
});
document.getElementById('exportButton').style.display = 'inline'; // 显示导出按钮
showToast("生成考号成功!", 2000); // 显示2秒
}
function showToast(message, duration) {
var toast = document.getElementById('toast');
toast.textContent = message;
toast.style.display = 'block';
setTimeout(function() {
toast.style.display = 'none';
}, duration);
}
function clearExamSeatsData() {
const table = document.getElementById('examData');
table.innerHTML = ''; // Clear all data
document.getElementById('exportButton').style.display = 'none'; // 隐藏导出按钮
}
function exportToExcel() {
const table = document.getElementById('examData');
const rows = table.getElementsByTagName('tr');
const data = [];
for (let i = 0; i < rows.length; i++) {
const cells = rows[i].getElementsByTagName('td');
const rowData = [];
for (let j = 0; j < cells.length; j++) {
rowData.push(cells[j].innerText);
}
data.push(rowData);
}
const ws = XLSX.utils.aoa_to_sheet([
['考场号', '座位号', '考号'],
...data
]);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, '考号数据');
XLSX.writeFile(wb, 'exam.xls');
}
// Function to set current year in footer
function setCurrentYear() {
const yearSpan = document.getElementById('year');
yearSpan.textContent = new Date().getFullYear();
}
// Set the current year when the page loads
window.onload = setCurrentYear;
</script>
</body>
</html>