随机点名系统

随机点名系统

<html>
	<head>
		<title>随机点名系统</title>
		<style type="text/css">
			body{
				background-color:pink;
			}
			h1{
				text-align:center;
			}
			#btn{
				width: 100px;
				height: 30px;
				//margin-left: 600px;
				//margin-top: 50px;
				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 arrs=["1","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","28"
			//,"29","30","31","32","33","34","35","36","37"];
			var boxNode=document.getElementById("box");
			for(var i=0;i<total;i++){
				//动态生成div
				var divNode=document.createElement("div");
				//divNode.innerHTML=arrs[i];
				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>

效果图

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值