抽奖

html部分:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>doris</title>
<link rel="stylesheet" style="text/css" href="b.css" />
<script type="text/javascript" src="b.js"></script>
</head>


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

</html>


css:


/* CSS Document */
*{
  margin:0;
  padding:0;
}
.title{
  width:400px;
  height:70px;
  margin:0 auto;
  text-align:center;
  font-size:24px;
  padding-top:25px;
  font-weight:bold;
  color:#f00;
}
.btns{
  width:190px;
  height:30px;
  margin:0 auto;
}
.btns span{
  display:block;
  float:left;
  width:75px;
  height:27px;
  background-color:#FF00FF;
  line-height:27px;
  text-align:center;
  margin-right:10px;
  border:1px solid #eee;
  border-radius:7px;
  font-size:14px;
  font-family:"微软雅黑";
  cursor:pointer;}



JS:


// JavaScript Document
var data=['毛绒玩具','步步高','钢笔','佳能相机','晴雨伞','谢谢参与','30元充值卡','500元超市购物券'],
    timer=null,
    flag=0;


window.οnlοad=function(){
    var play=document.getElementById('play'),
        stop=document.getElementById('stop');


    // 开始抽奖
    play.οnclick=playFun;
    stop.οnclick=stopFun;


   // 键盘事件
   document.οnkeyup=function(event){
      event = event || window.event;
      if(event.keyCode==13){
         if(flag==0){
           playFun();
           flag=1;
         }else{
           stopFun();
           flag=0;
         }
      }
   }
}


function playFun(){
var title=document.getElementById('title');
var play=document.getElementById('play');
clearInterval(timer);
timer=setInterval(function(){
  var random=Math.floor(Math.random()*data.length);
  title.innerHTML=data[random];
},50);
    play.style.background='#ccc';
}


function stopFun(){
clearInterval(timer);
var play=document.getElementById('play');
play.style.background='#FF00FF';
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值