<!doctype html><html><head><title>运动</title><meta charset="utf-8"><style>.div1{width:100px;height:100px;float:left;background:#ccc;margin:5px;}</style><script>window.onload=function(){ aDiv=document.getElementsByClassName('div1'); for(var i=0;i<aDiv.length;i++) {aDiv[i].onclick=function(){this.style.background="red";// aDiv[i].style.background="red"; //为什么不能这样写呢?} } }</script></head><body><div class="div1"></div><div class="div1"></div><div class="div1"></div><div class="div1"></div><div class="div1"></div><div class="div1"></div><div class="div1"></div><div class="div1"></div><div class="div1"></div><div class="div1"></div><div class="div1"></div><div class="div1"></div><div class="div1"></div><div class="div1"></div><div class="div1"></div></body></html>
添加回答
举报
0/150
提交
取消