Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions students.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@
button {
font-size: 2rem;
padding: 1rem 2rem;
margin-bottom: 1rem;
}
#result {
font-size: 2rem;
margin-top: 1rem;
}
input {
font-size: 2rem;
width: 100px;
text-align: center;
margin-bottom: 1rem;
}
</style>
</head>
<body>
<button onclick="document.getElementById('result').innerText = students[Math.floor(Math.random() * students.length)]">
<input type="number" id="count" value="1" min="1">
<button onclick="selectStudents()">
点名
</button>
<p id="result"></p>
Expand Down Expand Up @@ -131,7 +139,7 @@
"邹书承",
"吴永聪",
"肖淇",
"徐泓昊",
"23336017",
"薛炜鹏",
"张周骁",
"周子健",
Expand All @@ -154,6 +162,30 @@
"卢晓玲",
"吕振宁",
"郭靖宇"];
const input=document.getElementById('count');
input.max=students.length;
function selectStudents(){
if(students.length<=0)
{
alert("请上传学生名单");
return ;
}
let num=parseInt(input.value);
if(num>students.length)
{
alert("人数超出上限");
return;
}
num=Math.max(1,Math.min(num,students.length));
const temp=[...students];
const selected=[];
for (let i=0;i<num;i++){
const randomIndex=Math.floor(Math.random()*temp.length);
selected.push(temp.splice(randomIndex,1)[0]);
}
const resultElement=document.getElementById('result');
resultElement.innerText=selected.join(', ');
}
</script>
</body>
</html>