You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
select_random/score_display.html

198 lines
6.3 KiB

<!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: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #a18cd1, #fbc2eb);
height: 100vh;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
color: #333;
}
.container {
width: 90%;
max-width: 800px;
background: rgba(255, 255, 255, 0.85);
padding: 40px;
border-radius: 20px;
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
backdrop-filter: blur(8.5px);
-webkit-backdrop-filter: blur(8.5px);
border: 1px solid rgba(255, 255, 255, 0.18);
text-align: center;
}
h1 {
margin-bottom: 30px;
font-size: 2em;
color: #ff5722;
}
#sortButton {
padding: 10px 20px;
font-size: 1em;
border: none;
border-radius: 25px;
background-color: #2196F3;
color: white;
cursor: pointer;
transition: background-color 0.3s, transform 0.2s;
margin-bottom: 20px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}
#sortButton:hover {
background-color: #1e88e5;
transform: scale(1.05);
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3);
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 10px;
}
th, td {
padding: 12px 15px;
border-bottom: 1px solid #ddd;
font-size: 1em;
}
th {
background-color: #4CAF50;
color: white;
}
tr:hover {
background-color: #f1f1f1;
}
.button-group {
margin-top: 30px;
display: flex;
justify-content: space-between;
gap: 10px;
}
.back-button, .clear-button {
padding: 10px 20px;
font-size: 1em;
border: none;
border-radius: 25px;
color: white;
cursor: pointer;
transition: background-color 0.3s, transform 0.2s;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}
.back-button {
background-color: #2196F3;
}
.back-button:hover {
background-color: #1e88e5;
transform: scale(1.05);
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3);
}
.clear-button {
background-color: #f44336;
}
.clear-button:hover {
background-color: #e53935;
transform: scale(1.05);
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3);
}
@media (max-width: 600px) {
th, td {
padding: 8px 10px;
}
#sortButton, .button-group button {
width: 100%;
margin: 10px 0;
}
}
</style>
</head>
<body>
<div class="container">
<h1>积分显示</h1>
<button id="sortButton">切换排序 (降序)</button>
<table>
<thead>
<tr>
<th>姓名</th>
<th>积分</th>
</tr>
</thead>
<tbody id="studentList">
<!-- 学生积分将在此处显示 -->
</tbody>
</table>
<div class="button-group">
<button class="back-button" onclick="window.location.href='index.html'">返回主页面</button>
<button class="clear-button" id="clearButton">清除所有数据</button>
</div>
</div>
<script>
const studentList = document.getElementById('studentList');
const sortButton = document.getElementById('sortButton');
const clearButton = document.getElementById('clearButton');
let ascending = false; // 默认降序
// 预定义学生名单
const predefinedStudents = [
{ name: '张三', points: 0 },
{ name: '李四', points: 0 },
{ name: '王五', points: 0 },
{ name: '赵六', points: 0 },
];
// 获取所有学生,包括预定义名单
function getAllStudents() {
const students = predefinedStudents.map(student => {
const storedPoints = localStorage.getItem(student.name);
return {
name: student.name,
points: storedPoints !== null ? parseInt(storedPoints) : student.points
};
});
return students;
}
// 显示学生积分
function displayStudents() {
const students = getAllStudents();
students.sort((a, b) => ascending ? a.points - b.points : b.points - a.points);
studentList.innerHTML = '';
students.forEach(student => {
studentList.innerHTML += `
<tr>
<td>${student.name}</td>
<td>${student.points}</td>
</tr>
`;
});
}
// 切换排序
sortButton.addEventListener('click', () => {
ascending = !ascending;
sortButton.textContent = `切换排序 (${ascending ? '升序' : '降序'})`;
displayStudents();
});
// 清除所有数据
clearButton.addEventListener('click', () => {
const confirmation = confirm("确定要清除所有学生数据吗?此操作无法撤销!");
if (confirmation) {
localStorage.clear();
alert("所有数据已清除!");
displayStudents(); // 重新显示清空后的数据
}
});
// 初次加载时显示学生积分
displayStudents();
</script>
</body>
</html>