From 31fe8edcaa9805a62c5a7801498168c463d6cffd Mon Sep 17 00:00:00 2001
From: pzf8uwcp6 <13519963156@163.com>
Date: Sat, 12 Oct 2024 19:29:59 +0800
Subject: [PATCH] ADD file via upload
---
student.js | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+)
create mode 100644 student.js
diff --git a/student.js b/student.js
new file mode 100644
index 0000000..ecf8f2d
--- /dev/null
+++ b/student.js
@@ -0,0 +1,98 @@
+// 返回上一页
+function goBack() {
+ window.history.back();
+}
+
+function showMessage(text) {
+ const messageDiv = document.getElementById("message");
+ messageDiv.textContent = text;
+ messageDiv.style.display = "block"; // 显示消息
+
+ setTimeout(() => {
+ messageDiv.style.display = "none"; // 1秒后隐藏消息
+ }, 1000);
+}
+
+// 加载学生名单
+function loadStudentList() {
+ // 注册工具提示事件
+ registerTooltipEvents();
+ const students = JSON.parse(localStorage.getItem('students')) || [];
+ const list = document.getElementById('studentList');
+ list.innerHTML = '';
+
+ if (students.length === 0) {
+ list.innerHTML = '
尚未导入任何学生名单。
';
+ return;
+ }
+
+ // 积分从大到小排序学生
+ students.sort((a, b) => b.points - a.points);
+
+ students.forEach((student, index) => {
+ list.innerHTML += `
+
+ ${student.id} - ${student.name} - 积分: ${student.points}
+
+
+
`;
+ });
+ registerTooltipEvents();
+}
+
+function registerTooltipEvents() {
+ const buttons = document.querySelectorAll('button[data-tooltip]');
+ const tooltip = document.getElementById('tooltip');
+
+ buttons.forEach(button => {
+ button.addEventListener('mouseenter', function(event) {
+ tooltip.textContent = button.getAttribute('data-tooltip');
+ tooltip.style.display = 'block';
+ tooltip.style.left = event.pageX + 'px';
+ tooltip.style.top = (event.pageY + 20) + 'px'; // 鼠标下方略微偏移
+ });
+
+ button.addEventListener('mouseleave', function() {
+ tooltip.style.display = 'none';
+ });
+ });
+}
+
+// 清除单个学生积分
+function clearStudentPoints(index) {
+ const students = JSON.parse(localStorage.getItem('students')) || [];
+ students[index].points = 0; // 清除该学生的积分
+ localStorage.setItem('students', JSON.stringify(students)); // 更新本地存储
+ loadStudentList(); // 重新加载学生列表
+ showMessage("已清除该学生积分。");
+}
+
+// 删除单个学生
+function deleteStudent(index) {
+ let students = JSON.parse(localStorage.getItem('students')) || [];
+ students.splice(index, 1); // 删除该学生
+ localStorage.setItem('students', JSON.stringify(students)); // 更新本地存储
+ loadStudentList(); // 重新加载学生列表
+ showMessage("已删除该学生。");
+}
+
+// 一键清除所有学生的积分
+function resetAllPoints() {
+ let students = JSON.parse(localStorage.getItem('students')) || [];
+ students.forEach(student => student.points = 0); // 清除所有学生的积分
+ localStorage.setItem('students', JSON.stringify(students)); // 更新本地存储
+ loadStudentList(); // 重新加载学生列表
+ showMessage("所有学生的积分已清除。");
+}
+
+window.onload = loadStudentList; // 页面加载时调用
\ No newline at end of file