if(ev.keyCode==40) {inde
鍵盤事件中if(ev.keyCode==40) {index++;if(index>as.length){index=0;} for(var i=0;i<as.length;i++ ){as[i].style.backgroundColor="white";} as[index].style.backgroundColor="red";中這個as[i].style.backgroundColor="white"究竟是怎么起作用的?
鍵盤事件中if(ev.keyCode==40) {index++;if(index>as.length){index=0;} for(var i=0;i<as.length;i++ ){as[i].style.backgroundColor="white";} as[index].style.backgroundColor="red";中這個as[i].style.backgroundColor="white"究竟是怎么起作用的?
2018-01-30
舉報
2018-02-01
事件觸發(fā)時,函數(shù)中的代碼從上到下的運行。如果不遍歷菜單數(shù)組將每個選項的背景重置為白色,那么按一次向下鍵就有一個選項的背景色變紅,按完幾次后所有的選項都變紅了(用戶不知道自己此刻選中的是哪個選項),所以每次鍵盤按下之前要將之前按下的效果清空。