js,鼠标移入块控制另一块改变

<script>
  var a=document.getElementsByTagName('li')    定义一个变量找到当前文档内的li。
  for(i=0;i<a.length;i=i+1){                                      for循环
   a[i].onmouseover=function(){                             鼠标移入时间触发
    this.style.color='red'                                          当前域字体颜色变为红
    this.style.background='white'                            当前域背景变为白
   }
  }
  for(i=0;i<a.length;i=i+1){                                   for循环
   a[i].onmouseout=function(){                            鼠标移出事件触发
    this.style.color='white'                                     字体样式变为白
    this.style.background='#424242'                   背景样式变为#424242
   }
  }
 </script>

猜你喜欢

转载自www.cnblogs.com/fw282204258/p/10079417.html