所有div的class相同,所有a标签的class也相同,因为这块数据是循环读取的。
怎么才能实现点击第二个div然后对应第二个a标签的字体变成红色,第三个div对应第三个a标签这样。
<style>
.on{ background-color:#f00;}
</style>
<div class="this_img" onMouseOver="img()">1 </div>
<div class="this_img" onMouseOver="img()">2 </div>
<div class="this_img" onMouseOver="img()">3 </div>
<div class="this_img" onMouseOver="img()">4 </div>
<div class="this_img" onMouseOver="img()">5 </div>
<a class="s_img">aa</a>
<a class="s_img">ab</a>
<a class="s_img">ac</a>
<a class="s_img">ad</a>
<a class="s_img">ae</a>
<script>
function img(){
var this_img=document.getElementsByClassName('this_img');
var s_img=document.getElementsByClassName('s_img');
for(var i=0;i<this_img.length;i++){
this_img[i].onclick =function(){
this.className='on';
s_img[i].style.color="red";
};
}
}
</script>