关于js控制图层隐藏显示
为什么使用ID时候就可以,使用name属性的时候就不能用了?<html><head><SCRIPTLANGUAGE="JavaScript">window.onload=...
为什么使用ID时候就可以,使用name属性的时候就不能用了?
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
window.onload=function(){
var d1=document.getElementsByName("d1")
var d2=document.getElementsByName("d2")
var d3=document.getElementsByName("d3")
var d4=document.getElementsByName("d4")
var d5=document.getElementsByName("d5")
<!-- for(i=0;i<=d2.length;i++)
<!-- { d1.onmouseover=function(){
<!-- d2[i].style.display="block";
<!-- d3[i].style.display="block";
<!-- d4[i].style.display="block";
<!-- }
<!-- }
d1.onmouseover=function(){
d2.style.display="block";
d3.style.display="block";
d4.style.display="block";
};
d1.onmouseout=function(){
d2.style.display="none";
d3.style.display="none";
d4.style.display="none";
} ;
}
</SCRIPT>
<style type="text/css">
.c1{width:100px;height:100px;float:left;background:#999;}
.c2{width:100px;height:100px;float:left;background:#F00;display:none;}
.c3{width:100px;height:100px;float:left;background:#0F0;}
.c4{width:100px;height:100px;float:left;background:#00F;display:none;}
.c5{width:100px;height:100px;float:left;background:#FF0;display:none;}
</style>
</head>
<body>
<div class="c1" name="d1"></div>
<div class="c2" name="d2"></div>
<div class="c3" name="d3"></div>
<div class="c4" name="d4"></div>
<div class="c5" name="d5"></div>
</body>
</html> 展开
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
window.onload=function(){
var d1=document.getElementsByName("d1")
var d2=document.getElementsByName("d2")
var d3=document.getElementsByName("d3")
var d4=document.getElementsByName("d4")
var d5=document.getElementsByName("d5")
<!-- for(i=0;i<=d2.length;i++)
<!-- { d1.onmouseover=function(){
<!-- d2[i].style.display="block";
<!-- d3[i].style.display="block";
<!-- d4[i].style.display="block";
<!-- }
<!-- }
d1.onmouseover=function(){
d2.style.display="block";
d3.style.display="block";
d4.style.display="block";
};
d1.onmouseout=function(){
d2.style.display="none";
d3.style.display="none";
d4.style.display="none";
} ;
}
</SCRIPT>
<style type="text/css">
.c1{width:100px;height:100px;float:left;background:#999;}
.c2{width:100px;height:100px;float:left;background:#F00;display:none;}
.c3{width:100px;height:100px;float:left;background:#0F0;}
.c4{width:100px;height:100px;float:left;background:#00F;display:none;}
.c5{width:100px;height:100px;float:left;background:#FF0;display:none;}
</style>
</head>
<body>
<div class="c1" name="d1"></div>
<div class="c2" name="d2"></div>
<div class="c3" name="d3"></div>
<div class="c4" name="d4"></div>
<div class="c5" name="d5"></div>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询