window.onload = function(){ var myLi = document.getElementsByName('my'); for(var i = 0;i<myLi.length;i++){ myLi[i].onmouseover = function(){ this.style.background = "red"; //myLi[i].style.background = "red";//这个为什么不能用,myLi[i]是空 } } }
是不是标签没命名为"my"啊~~这点代码看不出啥