抽奖系统

play.html

<!doctype html>
<html>
<head>
	<title>抽奖</title>
	<meta charSet="UTF-8"/>
   <link type="text/css" rel="stylesheet" href="style.css">
   <script type="text/javascript" src="script.js"></script>
</head>

<body>
	<div id="title" class="title">开始抽奖啦!</div>
	<div class="btns">
		<span id="play">开 始</span>
		<span id="stop">停 止</span>
	</div>
	
</body>
</html>

script.js

var data=['Phone5','Ipad','三星笔记本','佳能相机','惠普打印机','谢谢参与','50元充值卡','1000元超市购物券'],
    timer=null,
    flag=0;
window.οnlοad=function(){
	var title=document.getElementById('title');
	var play=document.getElementById('play');
	var stop=document.getElementById('stop');
	//触发方法	
	play.οnclick=playFun;
	stop.οnclick=stopFun;

   // 键盘事件 Enter
   document.οnkeyup=function(event){ 
      event = event || window.event; 
      if(event.keyCode==13){
  		 if(flag==0){
           playFun();
           flag=1;
         }else{
           stopFun();
           flag=0;
         }
      }
   }
	//方法定义
	function playFun(){
		clearInterval(timer);
		timer=setInterval(function(){
	    var random=Math.floor(Math.random()*data.length);
	    title.innerHTML=data[random];
	},80);
	 stop.style.background='#036';
	 play.style.background='#999';
	}

	function stopFun(){
	  play.style.background='#036';
      stop.style.background='#999';
     clearInterval(timer);
 	}
}

style.css

*{margin:0;padding: 0;}
.title{width: 400px;
	height: 80px;
	margin: 0 auto;
	padding-top: 20px;
	text-align:center;
	font-size:24px;
	font-weight:bold;
	color:#F00;}
.btns{
	width: 200px;
	height: 40px;
	margin:0 auto;}

.btns span{
	display: block;
	float: left;
	width: 90px;
	height: 27px;
	line-height: 27px;

	background:#036;
	border-radius: 7px;
	margin-right: 10px;
	text-align: center;
	color: #FFF;
	text-align:center;
	font-size: 14px;
	font-family: "微软雅黑";
	cursor:pointer;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值