js 获取元素

<html>
<head>
<meta charset="utf-8">
<title>the test page</title>

 
</head>
<body style="margin:0;">  
    <div  id="div" style="background:#09F; 200px; margin:auto;white-space:nowrap; overflow:hidden; text-overflow:ellipsis; height:20px;border:1px solid red;">  这是一个可以自适应窗口的DIV   </div>  
    <div class="div1" style="background:#09F; 200px; margin:auto;white-space:nowrap; overflow:hidden; text-overflow:ellipsis; height:20px;border:1px solid red;">  这是一个可以自适应窗口的DIV   </div>  

    <div class="div1" style="background:#09F; 200px;  margin:auto;white-space:nowrap; overflow:hidden; text-overflow:ellipsis; height:20px;border:1px solid red;">  这是一个可以自适应窗口的DIV   </div>  

 <img src="thinkphp/Public/images/8.jpg" />
 <img src="6.jpg" />
 <img src="7.jpg" />
  
</body>  
</html>
<script>  
var n=document.getElementsByTagName("img").length;
var r=document.getElementsByTagName("img");
var div=document.getElementById("div");
var div1=document.getElementsByClassName("div1");
var ll=document.getElementsByClassName("div1").length;

div.onclick=function()
{
    for(var i=0;i<ll;i++)
    {
      div1[i].style.display="none";
    }
}

for(var i=0;i<ll;i++)
    {
               div1[i].onmousemove=function()
               {
                
                this.style.backgroundColor="red";
                
               }
                div1[i].onmouseout=function()
               {
                
                 this.style.backgroundColor="#FFF";
                
               }
               
    }
    
    
    
</script> 
原文地址:https://www.cnblogs.com/benpaodegegen/p/6407785.html