这个效果鼠标和键盘怎么才能搭配使用呢?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>键盘事件-按回车实现开始停止</title>
<style>
body,input{margin:0;padding:0;font-size:14px;font-family:"微软雅黑";}
#text{color:red;font:bold 32px/38px "微软雅黑";width:500px;height:38px;text-align:center;margin:30px auto;}
#box input{width:80px;font:16px/26px "微软雅黑";background:#036;color:#fff;float:left;margin-right:10px;border:none;border-radius:8px;text-align:center;cursor:pointer;}
#box{height:26px;width:180px;margin:0 auto;}
</style>
<script>
window.onload=function ()
{
var oText=document.getElementById('text');
var oStart=document.getElementById('start');
var oStop=document.getElementById('stop');
var timer=null;
var aText=['IPhone5s','IPad','三星笔记本','惠普打印机','吉列剃须刀','谢谢参与','50元电话卡','1000元超市购物卡'];
var onOff=true;
oStart.onclick=function ()
{
clearInterval(timer);
timer=setInterval(getRandom,50);
this.style.background='#999';
}
oStop.onclick=function (){
clearInterval(timer);
oStart.style.background='';
}
document.onkeyup=function (ev)
{
var ev=ev||event;
//alert(ev.keyCode) //回车是13
if(ev.keyCode==13)
{
if(onOff)
{
clearInterval(timer);
timer=setInterval(getRandom,50);
oStart.style.background='#ccc';
}
else
{
clearInterval(timer);
oStart.style.background='';
}
onOff=!onOff;
}
}
function getRandom()
{
var num=aText.length-1;
oText.innerHTML=aText[Math.round(Math.random()*num)];
}
}
</script>
</head>
<body>
<div id="text">开始抽奖啦!</div>
<div id="box">
<input type="button" value="开 始" id="start">
<input type="button" value="停 止" id="stop">
</div>
</body>
</html>