点名器,刚学习web,想写点东西就写个这个小玩意。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
.box{width: 200px; height: 200px ;color: red; background-color: aqua; float: left;}
.box2{width: 100px; height: 100px; background-color: red; }
.btn{width: 40px; height: 30px; background-color: red; color: azure; display: inline-block;
position: relative; left: 60px; top: 160px;}
</style>
</head>
<body>
<div class="box" id="box">
</div>
<button class="btn" id="btn"></button>
<script>
var oBox = document.getElementById("box");
var obtn = document.getElementById("btn");
var time;//点名计时器
var time1;//自动点击计时器
var b=true;
var a =["张三","李四","王五","马六","七八","九十","旺旺","小福贵"];//定义数组
time1 = setInterval(function(){
obtn.click();
}, 3000)//自动点击器 每隔3秒点击一下!不想要删掉就行
obtn.onclick =function(){
if(b){
b=false;
time = setInterval(function(){
oBox.innerHTML =a[Math.floor(Math.random()*(a.length-1))] //定义的名字随机出现
},20)
}else{
clearInterval(time);
oBox.innerHTML =a[Math.floor(Math.random()*(a.length-1))]
b=true;
}
}//随机点名方法 /采取点击一下开始,再次点击结束,方便快捷
</script>
</body>
</html>