抽奖.html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="index.css">
<script type="text/javascript" src="index.js"></script>
</head>
<body>
<div id="title" class="title">开始抽奖啦</div>
<div class="btns">
<span id="play">开始</span>
<span id="stop">结束</span>
</div>
</body>
</html>
 
index.js代码如下:
var data=['iPhone5','IPad','三星笔记本','佳能相机','惠普打印机'],
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;
console.log(event.keyCode);
if(event.keyCode==13)
{
if(flag==0){
playFun();
flag=1;
}
else {
stopFun();
flag = 0;
}
}
}
}
function playFun(){
//var that = this;
var title = document.getElementById('title');
var play = document.getElementById('play');
clearInterval(timer);
timer = setInterval(function(){
var random = Math.floor(Math.random()*data.length);
console.log(random);
title.innerHTML = data[random];
},50);
play.style.background ='#999';
}
function stopFun(){
clearInterval(timer);
var play = document.getElementById('play');
play.style.background ='#036';
}

index.css代码如下:

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

最新文章

  1. Eclipse 中文的设置
  2. jquery键盘事件总结
  3. Eclipse 配置Maven
  4. T-SQL利用Case When Then多条件判断
  5. java之RTTI和反射的理解
  6. DeepID人脸识别算法之三代(转)
  7. bzoj1752 [Usaco2005 qua]Til the Cows Come Home
  8. pycharm中的光标变粗的问题
  9. Checkbutton
  10. android binder机制详解
  11. RequestMapper
  12. Python基础——6面向对象编程
  13. python 更换 版本
  14. java源文件与类
  15. Installing PHP5 on Ubuntu Server
  16. 20155339平措卓玛 Exp1 PC平台逆向破解(5)M
  17. 【Android】12.1 Intent基本概念
  18. [转]git命令之git remote的用法
  19. 搭建Git Server - 个人开发简单搭建
  20. svn 冲突Skipped ‘inm/inm/templates‘ -- Node remains in conflict

热门文章

  1. 1-hadoop、mr
  2. vs与linux的交叉编译环境搭建
  3. android 开发 我的高德地图代码例子
  4. Spring MVC和Spring Boot的理解以及比较
  5. Vue proxy
  6. 4-29 c语言之栈,队列,双向链表
  7. 安装和激活Office 2019
  8. 查找单链表中倒数第K个位置上的结点,若查找成功返回该节点的data域,若不成功只返回0
  9. MFC之sqlite
  10. db2 SQL6036N解决办法