可以添加成员,成员名称自定义
可以对各个成员加分减分➕➖
可以删除成员
源码在图片下面,记得点赞加关注❤️❤️❤️
界面
源代码
<!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: #f8f9fa;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.container {
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
width: 80%;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
button {
background-color: #dc3545;
color: white;
border: none;
padding: 5px 10px;
border-radius: 5px;
cursor: pointer;
margin-right: 5px;
}
button:hover {
background-color: #c82333;
}
.add-member {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="container">
<h2>在线积分系统</h2>
<div class="add-member">
<input type="text" id="memberName" placeholder="输入成员名称">
<button οnclick="addMember()">添加成员</button>
</div>
<table>
<thead>
<tr>
<th>成员</th>
<th>分数</th>
<th>操作</th>
</tr>
</thead>
<tbody id="membersTableBody">
</tbody>
</table>
</div>
<script>
const membersTableBody = document.getElementById('membersTableBody');
const memberNameInput = document.getElementById('memberName');
const members = [];
function addMember() {
const memberName = memberNameInput.value.trim();
if (memberName) {
members.push({ name: memberName, score: 0 });
memberNameInput.value = '';
renderMembers();
}
}
function removeMember(memberIndex) {
members.splice(memberIndex, 1);
renderMembers();
}
function adjustScore(memberIndex, delta) {
members[memberIndex].score += delta;
renderMembers();
}
function renderMembers() {
membersTableBody.innerHTML = '';
members.forEach((member, index) => {
const row = `
<tr>
<td>${member.name}</td>
<td>${member.score}</td>
<td>
<button οnclick="adjustScore(${index}, 1)">+1</button>
<button οnclick="adjustScore(${index}, -1)">-1</button>
<button οnclick="removeMember(${index})">删除</button>
</td>
</tr>
`;
membersTableBody.insertAdjacentHTML('beforeend', row);
});
}
// 初始化渲染成员列表
renderMembers();
</script>
</body>
</html>