抽奖——键盘事件
标签:
JavaScript
var data=['Phone5','Ipad','三星笔记本','佳能相机','惠普打印机','谢谢参与','50元充值卡','1000元超市购物券'],
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();
}else {
stopFun();
}
}
}
};
function playFun() {
var play=document.getElementById('play');
var title=document.getElementById('title');
clearInterval(timer);
timer=setInterval(function () {
var random=Math.floor(Math.random()*data.length);
title.innerHTML=data[random];
},50);
play.style.background='#999';
flag=1;
}
function stopFun() {
var play=document.getElementById('play');
clearInterval(timer);
play.style.background='#036';
flag=0;
}点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦