为什么我的键盘事件不响应?
var data=['三星','惠普','联想','谢谢惠顾','苹果','华硕','海尔电冰箱','谢谢惠顾'],
timer=null,
flag=0;
window.onload=myFun;
function myFun () {
// body...
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();
flag=1;
}
else{
stopFun();
flag=0;
}
}
}
}
function playFun () {
var title=document.getElementById('title'),
play=document.getElementById('play');
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="#036";
}