想写个循环测试一下onmouseout,onmouseover,下面是具体代码。
下面这段代码不能正常执行
var yy = document.getElementsByClassName("div_inTop_001"); for (var i = 0; i < yy.length; i++) { yy[i].addEventListener("mouseover", myfunction0000); yy[i].addEventListener("mouseout", myfunction0001); function myfunction0000(){ yy[i].style.backgroundColor="#A52A2A"; console.log(i); } function myfunction0001(){ yy[i].style.backgroundColor="#5B5B5B"; console.log(i); } } 可以正确执行的代码:var yy = document.getElementsByClassName("div_inTop_001"); for (var i = 0; i < yy.length; i++) { yy[i].addEventListener("mouseover", myfunction0000); yy[i].addEventListener("mouseout", myfunction0001); function myfunction0000(){ this.style.backgroundColor="#A52A2A"; console.log(i); } function myfunction0001(){ this.style.backgroundColor="#5B5B5B"; console.log(i); } } 我想知道为什么上面的那一段代码不能运行?下面那段代码为什么能运行 yy.length=5
相关分类