[HTML] 纯文本查看 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.dian {
margin: 100px auto;
border: 1px solid red;
width: 100px;
height: 100px;
text-align: center;
line-height: 100px;
color: red;
}
</style>
</head>
<body>
<button>开始点名</button>
<button>结束点名</button>
<div class="dian">小王</div>
<script>
var arr = ['小王','小李','小黑','小李1','小黑2','小李3','小黑4','小李5','小黑6'];
var dian = document.querySelector('.dian');
var btnOne = document.getElementsByTagName('button')[0];
var btnTwo = document.getElementsByTagName('button')[1];
var timer;
dian.innerHTML = arr[parseInt(Math.random()*8)];
btnOne.onclick = function() {
timer = setInterval(function() {
dian.innerHTML = arr[parseInt(Math.random()*8)];
},10);
}
btnTwo.onclick = function() {
clearInterval(timer);
}
</script>
</body>
</html>
思路:1、定时器 2、随机数(random)3、数组。
以上是自己的思路,觉得好的给个热心哦。 |