<title>随机点名(拓展)</title>
<style>
* {
margin: 0;
padding: 0;
}
h2,
.btns {
text-align: center;
}
.box {
width: 600px;
margin: 50px auto;
display: flex;
font-size: 25px;
line-height: 40px;
}
.qs {
width: 450px;
height: 40px;
color: red;
}
.btns button {
width: 120px;
height: 35px;
margin: 0 50px;
}
</style>
</head>
<body>
<h2>随机点名</h2>
<div class="box">
<span>名字是:</span>
<div class="qs">这里显示姓名</div>
</div>
<div class="btn">
<button class="start">开始</button>
<button class="end">结束</button>
</div>
<script>
let arr = ['鲍中义', '陈琳', '常琴娜', '崔文昊', '陈晓丹', '丁克磊', '洞鸣威', '董思雨', '傅玉洁', '高浩', '黄盼月', '黄小龙', '何肖肖', '胡月', '纪宗锋', '刘锦程', '李静怡', '李龙', '陆铭雪', '刘娜', '李晓枫', '马曼婷', '盘进进', '庞雅静', '邱雨嫣', '宋佳豪', '盛也', '孙雨晴', '施雨彤', '陶鑫凯', '武国庆', '王国志', '文静', '温群和', '吴宛励', '汪万元', '王一轩', '王志强', '谢蝶蝶', '徐娟', '袁兴', '余湘湘', '杨雅丽', '张军', '张瑶瑶', '周雨晨'];
let random = 0;
function getRandom(min,max){
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max-min+1))+min;
}
let box=document.querySelector('div');
let btn= document.querySelector('button');
btn.addEventListener('click',function(){
let random= getRandom(0,arr.length-1);
box.innerHTML=arr[random];
arr.splice(random,1);
if(arr.length==0){
btn.disabled=true;
box.innerHTML='点名结束!'
}
})
</script>
</body>
</html>
随机点名(拓展) - 个人