显示层的问题
部分代码:
<script language= "javascript " type= "text/javascript ">
function fc&gg(i)
{
for(j=1;j <3;j++)
{
if(i==1)
{
document.getElementsByID( "div "+j).style.visibility = "visible ";
}
else
{
document.getElementsByID( "div "+j).style.visibility = "hidden ";
}
}
}
</script>
<style type= "text/css ">
<!--
A:link{color: #000000;text-decoration:none}
A:visited{color: #000000;text-decoration:none}
A:hover {color: #000000;text-decoration:none}
#div1{position:absolute; z-index:1;visibility:visible;}
#div2{position:absolute;z-index:2;visibility:hidden;}
-->
</style>
<table>
<tr>
<td style= "width: 200px ">
<a href= "# " onmouseover= "fc&gg( '1 ') "> 房产资讯 </a>
<a href= "# " onmouseover= "fc&gg( '2 ') "> 公告栏 </a>
</td>
</tr>
<tr>
<td>
<div id= "div1 "> //层1,内容省略
<div id= "div2 "> //层2,内容省略
</td>
</tr>
</table>
按说应该是鼠标指向“房产资讯”显示层1的内容,指向“公告栏”显示层2的内容。
现在页面只显示层1,指向“公告栏”没变化。
大虾来帮我看看哪错了。
------解决方案--------------------
1.函数名中不要用& , &是操作符
2.getElementsByID写错了,是getElementsById
[解决办法]
(1)函数名不能用&
(2)getElemementsById应为getElementById(注意,没s,还有大小写)
(3)函数中没有令div2的style.visibility=visible的语句。判断应该写成:
当i==1时,div1显示,div2隐藏
当i==2时,div1隐藏,div2显示
依次类推,有多个div时,当i==n时,divn显示,其它div隐藏
在此例中只有两个div的情况下,比较简单,
<script language= "javascript " type= "text/javascript ">
function fcgg(i){
switch (i){
case '1 ':document.getElementByID( "div1 ").style.visibility = "visible ";
document.getElementByID( "div2 ").style.visibility = "hidden ";
break;
case '2 ':document.getElementByID( "div2 ").style.visibility = "visible ";
document.getElementByID( "div1 ").style.visibility = "hidden ";
break;
}
}
</script>