<script type="text/javascript">
var date=['手机','电脑','手表','相机','打印机','谢谢参与','50元充值卡','1000元购物卷']
timer=null;
flog=true;
window.onload=function()
{
var play=document.getElementById('play');
var stop=document.getElementById('stop');
play.onclick=playfun;
stop.onclick=stopfun
document.onkeyup= function (event)
{
event=event || window.event;
if(event.keyCode==13)
{
if(flog==true)
{
playfun();
flog=false
}
}
else
{
stopfun();
flog=true
}
}
function playfun()
{
var that=this;
var title=document.getElementById('title');
clearInterval(timer);
timer=setInterval(function()
{
var random=Math.floor(Math.random()*date.length);
title.innerHTML=date[random];
},200);
play.style.background='#999'
}
function stopfun()
{
clearInterval(timer);
var play=document.getElementById('play');
play.style.background='#0077b3'
}
};
// 开始抽奖
if(event.keyCode==13) { if(flog==true) { playfun(); flog=false } } else { stopfun(); flog=true }
这里else的位置错了,你这样是按其他键停止
修改如下
if(event.keyCode==13) { if(flog==true) { playfun(); flog=false } else { stopfun(); flog=true } }