<!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>Document</title>
<style>
#one{
width:200px;
height:200px;
font-size:40px;
font-weight:bold;
border:1px solid #000;
text-align:center;
line-height:200px;
}
</style>
</head>
<body>
<div id="one">点名</div>
<button id="start">开始</button>
<button id="stop">停止</button>
</body>
<script>
let one=document.getElementById("one");
let start=document.getElementById("start");
let stop=document.getElementById("stop");
let name=["2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27"];
let time;
start.onclick=function () {
start.disabled=true;
time=setInterval(() => {
names();
}, 1);
}
stop.onclick=function () {
start.disabled=false;
clearInterval(time);
}
function names() {
let num=Math.floor(Math.random()*name.length);
let a=name[num];
one.innerHTML=a;
}
</script>
</html>
JS写的简易点名器
最新推荐文章于 2024-02-27 16:51:47 发布