<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h2>点击到的名字:<span></span></h2>
<button >开始点名</button>
</body>
<script type="text/javascript">
var arr=["崔星宇","刘子煜","陈琪","泊然","王世麒"]
var btn=document.querySelector("button");
var span=document.querySelector("span");
var clock;
btn.onclick=function(){
if(btn.innerHTML=="开始点名")
{
clock=setInterval(function(){
var a=parseInt(Math.random()*4);
span.innerHTML=arr[a];
},100)
btn.innerHTML="结束点名"
}
else{
clearInterval(clock);
btn.innerHTML="开始点名";
}
}
</script>
</html>
原文:https://www.cnblogs.com/chenaiiu/p/12257977.html