<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.form{
width: 150px;
height: 150px;
margin: 0 auto;
border: 1px solid black;
}
.text{
width: 150px;
height: 120px;
background-color: #f6e6ec;
font-size: 25px;
line-height: 120px;
text-align: center;
}
button{
width: 150px;
height: 30px;
}
</style>
</head>
<body>
<div class="form">
<div class="text">
点击按钮点名
</div>
<button>随机点名</button>
</div>
<script>
var stus = [];
var count = 10;
for(var i = 0; i < count; i++){
stus[i] = "学生" + (i + 1);
}
document.querySelector("button").onclick = function (){
var random = parseInt(Math.random() * count);
document.querySelector(".text").innerText = stus[random];
stus.splice(random,1);
count--;
if (count == 0){
this.disabled = true;
}
}
</script>
</body>
</html>
随机点名随机点名
最新推荐文章于 2024-04-22 23:06:24 发布