<!doctype?html>
<html>
<head>
<meta?charset="utf-8">
<title>無標題文檔</title>
<style?type="text/css">
*{?margin:0;?padding:0}
.title{?width:200px;?height:50px;?color:#F90307;?font-size:30px;?margin:0?auto;?padding-top:10px}
.btns{?width:150px;?height:50px;?margin:0?auto}
.btns?span{width:40px;?height:25px;?line-height:25px;?background:blue;?border:1px?#04052E?solid;?border-radius:5px;?color:#fff;?text-align:center;?font-size:14px;?display:block;?float:left;?cursor:pointer;margin-right:10px}
</style>
<script?type="text/javascript">
var?data?=?['謝謝參與','蘋果筆記本','佳能相機','惠普打印機','智能手機','50元充值卡','1000元購物券','再抽一次'];
var?timer?=?null;
var?flag?=?0;
window.onload?=?function(){
var?play?=?document.getElementById('play');
var?stop?=?document.getElementById('stop');
play.onclick?=?playFun;????//開始抽獎
stop.onclick?=?stopFun;????//停止抽獎
document.onkeyup?=?function(event){????//鍵盤事件
var?event?=?event?||?window.event;
if(event.keyCode?==?13){
playFun();
flag?=?1;
}else{
stopFun();
flag?=?0;
}
}
}
function?playFun(){
var?that?=?this;?//函數(shù)從哪調(diào)用的,this就是誰
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?=?'#999';
}
function?stopFun(){
clearInterval(timer);
var?play?=?document.getElementById('play');
play.style.background?=?'blue';
}
</script>
</head>
<body>
<div?id="title"?class="title">開始抽獎了!</div>
<div?class="btns">
<span?id="play">開始</span>
????<span?id="stop">停止</span>
</div>
</body>
</html>
為什么運行后按下鍵盤回車鍵抽獎不停止?
亞努人
2016-01-14 20:39:27