<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>随机点名册</title>
</head>
<body>
<div id="box">
<button id="start">开始</button>
<button id="end">结束</button>
<p></p>
</div>
</body>
<script>
let nameLists = ['张三','李四','王五','燕小六','虞小七','刘十三','茅十八']
let start = document.getElementById('start')
let end = document.getElementById('end')
let timer = null
start.onclick = function(){
clearInterval(timer)
timer = setInterval(function(){
num = Math.floor(7*Math.random(0,1))
console.log(num)
end.nextElementSibling.innerText = '选到了'+nameLists[num]
},100)
}
end.onclick = function(){
clearInterval(timer)
}
</script>
</html>