????????var hom = document.getElementById("home");? ? ? ? var ali = document.getElementsByTagName("li");? ? ? ? var adiv = hom.getElementsByTagName("div");// ? ? 使用for循環(huán),點擊沒有任何反應(yīng);? ? ? ? for(var i=0; i<ali.length; i++){? ? ? ? ? ? ali[i].onclick = function(){? ? ? ? ? ? ? ? ali[i].setAttribute("class","one");? ? ? ? ? ? ? ? adiv[i].setAttribute("class","");? ? ? ? ? ? }? ? ? ? }//這樣用就可以:?? ? ali[1].onclick = function(){? ? ? ? ? ? ? ? ali[1].setAttribute("class","one");? ? ? ? ? ? ? ? adiv[1].setAttribute("class","");? ? ? ? ? ? }
使用for循環(huán)點擊為什么沒有反應(yīng)?
singerow
2016-06-03 13:50:59