為什么我的鍵盤事件不響應?
var data=['三星','惠普','聯(lián)想','謝謝惠顧','蘋果','華碩','海爾電冰箱','謝謝惠顧'],
??? 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";
}
2016-11-17
keyCode中的k要小寫