html实现一个随机学生点名系统,随机抽取一个学生显示到屏幕中间
时间: 2024-01-17 20:59:01 浏览: 80
<!DOCTYPE html>
<html>
<head>
<title>随机学生点名系统</title>
<style>
body {
font-family: Arial, sans-serif;
font-size: 24px;
background-color: #f2f2f2;
}
.center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<div class="center">
<button onclick="randomStudent()">点名</button>
<p id="studentName"></p>
</div>
<script>
var students = ["小明", "小红", "小刚", "小丽", "小华", "小李", "小王", "小张", "小赵", "小钱"]; // 学生数组
function randomStudent() {
var randomIndex = Math.floor(Math.random() * students.length); // 生成随机数
document.getElementById("studentName").innerHTML = students[randomIndex]; // 显示随机学生名字
}
</script>
</body>
</html>
阅读全文