html随机抽奖

 有两个地方namelist你需要修改

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>随机点名器</title>
		<style type="text/css">
			#parent {
				background-color:#fdacfa ;
				height: 500px;
				border-radius: 10px;
				width: 700px;
				margin: 100px auto;
				position: relative;
			}
	
			#box {
				margin: auto;
				width: 400px;
				font-size: 66px;
				border: 1px ;
				font-weight: bold;
				height: 94px;
				border-radius: 20px;
				text-align: center;
				background-color: antiquewhite;
				position: absolute;
				margin-top: 100px;
				margin-left: 140px;
			}
	
			#bt {
				margin: auto;
				border-radius: 10px;
				border:0;
				background-color: white;
				width: 200px;
				text-align: center;
				margin-top: 300px;
				margin-left: 100px;
				color: #070000;
				font-weight: bold;
				font-size: 25px;
				cursor: pointer;
			}
	
			#box2{ 
				margin:AUTO;
				text-align: center;
				/*background:red;*/
			}
			
			#desc {
				border-radius: 10px;
				background-color:#fdacfa ;
				width: 600px;
				text-align: center;
				margin-top: 200px;
				margin-left: 60px;
				color: #070000;
				/*font-weight: bold;*/
				font-size: 20px;
				cursor: pointer;
			}
	
			#reset1 {
				border-radius: 10px;
				background-color: white;
				width: 200px;
				text-align: center;
				border-radius: 10px;
				border: 0px ;
				font-weight: bold;
				/*margin-top: 400px;*/
				/*margin-left: 60px;*/
				color: #070000;
				/*font-weight: bold;*/
				font-size: 25px;
				cursor: pointer;
			}
		</style>
	</head>
	
	<body>
		<div id="parent">
			<div id="box">随机抽奖</div>
			<div id="box2">
				<button id="reset1" onclick="rest1()">
					重置程序
				</button>
			<button id="bt" onclick="doit()">开始</button>
		</div>
			<div id="desc">
				每次得到一个人后将移除这个人,相当于抽奖。
			</div>
		</div>
	</body>
	
	<script type="text/javascript">
		//变量池[这个地方你要修改成你自己的数据]
		var namelist = ["Kiwa Jo", "阿瑶", "晴", "Lily Xu" , "Nana Chow"];
		//计时器
		var mytime = null;
	
		function doit() {
			var bt = window.document.getElementById("bt");
			if (mytime == null) {
				bt.style.backgroundColor = "#ff0000";
				bt.innerHTML = "停止";
				show();
			} else {
				bt.style.backgroundColor = "white";
				bt.innerHTML = "开始";
				clearTimeout(mytime);
				mytime = null;
				var box = window.document.getElementById("box");
				var name = box.innerText;
				var index = namelist.indexOf(name);
				namelist.splice(index,1);
			}
		}
	
		function show() {
			//获取目标
			var box = window.document.getElementById("box");
			//产生随机数
			var num = Math.floor((Math.random() * 100000)) % namelist.length;
			if(namelist.length <= 0){
				box.innerHTML = "没有人了";
			}else {
				//将随机的名字填入对应区域
				box.innerHTML = namelist[num];
			}
			//递归,自己调用自己
			mytime = setTimeout("show()", 10);
		}
	
		// 重置
		function rest1() { 
		var bt = window.document.getElementById("bt");
		bt.style.backgroundColor = "white";
				bt.innerHTML = "开始";
				clearTimeout(mytime);
				mytime = null;
			//[这个地方你要修改成你自己的数据]
			namelist = ["Kiwa Jo", "阿瑶", "晴", "Lily Xu" , "Nana Chow"];
			var box = window.document.getElementById("box");
			box.innerHTML = "继续";
		}
	</script>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值