抽奖
2016-07-30 16:23
211 查看
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.onload=function(){
var play=document.getElementById('play'),
stop=document.getElementById('stop');
// 开始抽奖
play.onclick=playFun;
stop.onclick=stopFun;
// 键盘事件
document.onkeyup=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';
}
<!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.onload=function(){
var play=document.getElementById('play'),
stop=document.getElementById('stop');
// 开始抽奖
play.onclick=playFun;
stop.onclick=stopFun;
// 键盘事件
document.onkeyup=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';
}
相关文章推荐
- 3月13日 抽奖活动
- 抽奖系统数据库设计
- jQuery幸运大转盘_jQuery+PHP抽奖程序
- Javascript函数[实用案例--网页抽奖]
- 第六次Java作业抽奖程序
- 九宫格抽奖停止位置的设置
- 小抽奖
- android微信摇一摇(抽奖)
- app H5活动抽奖活动(转盘)前端+后台设计
- 抽奖-高并发
- Cocos Creator轮盘抽奖
- iwebshop功能添加--积分抽奖(生成代金券)
- 抽奖活动中的学习
- 做一个【抽奖】
- java抽奖算法
- java抽奖算法
- 抽奖概率计算
- C#&PHP&Java实现Alias Method概率抽奖算法
- 微信小程序开发之大转盘 仿天猫超市抽奖
- MFC实现简单的,会抽奖程序