為什么按回車鍵不停止
<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'
? ? ? ?}
? ?};
? ?// 開始抽獎
2015-12-23
這里else的位置錯了,你這樣是按其他鍵停止
修改如下