?document.onkeydown=function(){
????????if?(event.keyCode==40){
????????????as[index].style.backgroundColor="#fff";
????????????if(index==4){
????????????????index=0;
????????????}
????????????else{
????????????????index++;
????????????}
????????}
????????if?(event.keyCode==38){
????????????as[index].style.backgroundColor="#fff";
????????????if(index>0){
????????????????index--
????????????}
????????????else{
????????????????index=as.length-1;
????????????}
????????}
????????as[index].style.backgroundColor="#456";
????}
2018-03-04
document.onkeydown=function(event){ ????for(var?i=0;i<as.length;i++){ ????????as[i].style.background="none" ????} ????if?(event.keyCode==40){ ????????if(index>=4){ ????????????index=0; ????????} ????????else{ ????????????index++; ????????} ????????as[index].style.background="#456"; ????????console.log(index) ????} ????if?(event.keyCode==38){ ????????if(index<=0){ ????????????index=as.length-1; ????????} ????????else{ ????????????index--; ????????} ????????as[index].style.background="#456"; ????} }2018-03-04
對了你還有個參數沒寫 ? ? event
2018-03-04
這次試過了 ?
這一句 ?as[index].style.backgroundColor="#fff";
還有你的判斷 ?
2018-03-04
if?(event.keyCode==38){ ????????????as[index].style.backgroundColor="#fff"; ????????????if(index=0){ ????????????????index=as.length-1; ????????????} ????????????else{ ????????????????index-- ????????????} ????????}這樣試試