随机点名系统
<html>
<head>
<title>随机点名系统</title>
<style type="text/css">
body{
background-color:pink;
}
h1{
text-align:center;
}
#btn{
width: 100px;
height: 30px;
margin:50px 600px ;
background:hotpink;
}
.box{
width: 1000px;
height: 260px;
margin: 0 auto;
margin-top: 100px;
clear: both;
}
.name{
width: 100px;
height: 30px;
float: left;
background-color: antiquewhite;
margin-left: 10px;
margin-top: 10px;
text-align: center;
line-height: 30px;
margin:10px 10px;
}
#btn:hover{
background:pink;
}
</style>
</head>
<body>
<h1>随机点名系统</h1>
<div class="box" id="box"></div>
<input type="button" value="点名" id="btn">
<script type="text/javascript">
var timeId;
var total=37;
var boxNode=document.getElementById("box");
for(var i=0;i<total;i++){
var divNode=document.createElement("div");
if(i<9){
divNode.innerHTML="0"+(i+1);
}else{
divNode.innerHTML=i+1;
}
divNode.className="name";
boxNode.appendChild(divNode);
}
var btn=document.getElementById("btn");
btn.onclick=function(){
if(this.value=="开始"){
timeId=setInterval(function(){
for(var j=0;j<total;j++){
boxNode.children[j].style.background="";
};
var random=parseInt(Math.random()*total+1);
boxNode.children[random].style.background="red";
},0);
this.value="停止";
}else{
clearInterval(timeId);
this.value="开始";
}
}
</script>
</body>
</html>