同一个页面设置多个滑动门

这是我做的CSS滑动门,在同个页面的两个滑动门
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>滑动门</title>
<style media="screen" type="text/css">
<!--
*{font-size:12px;}
html,body{margin:0;text-align:center;over-flow:hidden;height:100%;width:100%;}
UL{list-style-type:none; margin:0px;}
/* 标准盒模型 */
.ttl{height:18px;}
.ctt{height:auto;padding:6px;clear:both;border:1px solid #064ca1;border-top:0;text-align:left;}
.w936{margin:2px 0;clear:both;width:240px;/*滑动门的宽度*/}
/* TAB 切换效果 */
.tb_{background-image: url('http://www.pub.work.zjol.com.cn/ttxw/ztxl/gb/images/tb1.gif'); background-repeat: repeat-x;background-color: #E6F2FF;}
.tb_ ul{height:24px;}
.tb_ li{float:left;height: 24px;line-height:1.9;width: 80px;cursor:pointer;}
/* 控制显示与隐藏css类 */
.normaltab { background-image:url('http://www.pub.work.zjol.com.cn/ttxw/ztxl/gb/images/tb2.gif'); background-repeat: no-repeat; color:#1F3A87 ;}
.hovertab { background-image: url('http://www.pub.work.zjol.com.cn/ttxw/ztxl/gb/images/tb3.gif'); background-repeat: no-repeat; color:#1F3A87; font-weight:bold }
.dis{display:block;}
.undis{display:none;}
-->
</style>
<script type="text/javascript" language="javascript">
//<!CDATA[
function g(o){return document.getElementById(o);}
function HoverLi(n){
//如果有N个标签,就将i<=N;
for(var i=1;i<=6;i++){g('tb_'+i).className='normaltab';g('tbc_0'+i).className='undis';}g('tbc_0'+n).className='dis';g('tb_'+n).className='hovertab';
}
//如果要做成点击后再转到请将<li>中的onmouseover 改成 onclick;
//]]>
</script>
</head>
<body>
<div class="w936">
<div id="tb_" class="tb_">
<ul>
<li id="tb_1" class="hovertab" onmouseover="HoverLi(1);">
国内新闻</li>
<li id="tb_2" class="normaltab" onmouseover="HoverLi(2);">
国际新闻</li>
<li id="tb_3" class="normaltab" onmouseover="HoverLi(3);">
图说新闻</li>
</ul>
</div>
<div class="ctt">
<div class="dis" id="tbc_01">这里是ASP.NET的相关内容</div>
<div class="undis" id="tbc_02">这里是MYSQL的相关内容</div>
<div class="undis" id="tbc_03">这里是DELPHI的相关内容</div>
</div>
</div>
<div class="w936">
<div id="tb_" class="tb_">
<ul>
<li id="tb_4" class="hovertab" onmouseover="HoverLi(4);">
国内新闻</li>
<li id="tb_5" class="normaltab" onmouseover="HoverLi(5);">
国际新闻</li>
<li id="tb_6" class="normaltab" onmouseover="HoverLi(6);">
图说新闻</li>
</ul>
</div>
<div class="ctt">
<div class="dis" id="tbc_04">这里是ASP.NET的相关内容</div>
<div class="undis" id="tbc_05">这里是MYSQL的相关内容</div>
<div class="undis" id="tbc_06">这里是DELPHI的相关内容</div>
</div>
</div>
</body>
</html>
当鼠标放在一个滑动门时,另一个的内容就没了。有没有解决方法?我想设置多个这样的,还请高手帮忙解决

第1个回答  推荐于2016-03-01
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>滑动门</title>
<style media="screen" type="text/css">
<!--
*{font-size:12px;}
html,body{margin:0;text-align:center;over-flow:hidden;height:100%;width:100%;}
UL{list-style-type:none; margin:0px;}
/* 标准盒模型 */
.ttl{height:18px;}
.ctt{height:auto;padding:6px;clear:both;border:1px solid #064ca1;border-top:0;text-align:left;}
.w936{margin:2px 0;clear:both;width:240px;/*滑动门的宽度*/}
/* TAB 切换效果 */
.tb_{background-image: url('http://www.pub.work.zjol.com.cn/ttxw/ztxl/gb/images/tb1.gif'); background-repeat: repeat-x;background-color: #E6F2FF;}
.tb_ ul{height:24px;}
.tb_ li{float:left;height: 24px;line-height:1.9;width: 80px;cursor:pointer;}
/* 控制显示与隐藏css类 */
.normaltab { background-image:url('http://www.pub.work.zjol.com.cn/ttxw/ztxl/gb/images/tb2.gif'); background-repeat: no-repeat; color:#1F3A87 ;}
.hovertab { background-image: url('http://www.pub.work.zjol.com.cn/ttxw/ztxl/gb/images/tb3.gif'); background-repeat: no-repeat; color:#1F3A87;

font-weight:bold }
.dis{display:block;}
.undis{display:none;}
-->
</style>
<script type="text/javascript" language="javascript">
//<!CDATA[
function g(o){return document.getElementById(o);}
function HoverLi(n){
//如果有N个标签,就将i<=N;
for(var i=1;i<=3;i++){g('tb_'+i).className='normaltab';g('tbc_0'+i).className='undis';}g('tbc_0'+n).className='dis';g('tb_'+n).className='hovertab';
}
function OutHover(n)
{
g('tb_'+n).className='normaltab';
}
function HoverLi2(n)
{
for(var i=4;i<=6;i++){g('tb_'+i).className='normaltab';g('tbc_0'+i).className='undis';}g('tbc_0'+n).className='dis';g('tb_'+n).className='hovertab';
}
//如果要做成点击后再转到请将<li>中的onmouseover 改成 onclick;
//]]>
</script>
</head>
<body>
<div class="w936">
<div id="tb_" class="tb_">
<ul>
<li id="tb_1" class="hovertab" onmouseover="HoverLi(1);" onmouseout="OutHover(1)">
国内新闻</li>
<li id="tb_2" class="normaltab" onmouseover="HoverLi(2);" onmouseout="OutHover(2)">
国际新闻</li>
<li id="tb_3" class="normaltab" onmouseover="HoverLi(3);" onmouseout="OutHover(3)">
图说新闻</li>
</ul>
</div>
<div class="ctt">
<div class="dis" id="tbc_01">这里是ASP.NET的相关内容</div>
<div class="undis" id="tbc_02">这里是MYSQL的相关内容</div>
<div class="undis" id="tbc_03">这里是DELPHI的相关内容</div>
</div>
</div>
<div class="w936">
<div id="tb_" class="tb_">
<ul>
<li id="tb_4" class="hovertab" onmouseover="HoverLi2(4);" onmouseout="OutHover(4)">
国内新闻</li>
<li id="tb_5" class="normaltab" onmouseover="HoverLi2(5);" onmouseout="OutHover(5)">
国际新闻</li>
<li id="tb_6" class="normaltab" onmouseover="HoverLi2(6);" onmouseout="OutHover(6)">
图说新闻</li>
</ul>
</div>
<div class="ctt">
<div class="dis" id="tbc_04">这里是ASP.NET的相关内容</div>
<div class="undis" id="tbc_05">这里是MYSQL的相关内容</div>
<div class="undis" id="tbc_06">这里是DELPHI的相关内容</div>
</div>
</div>
</body>
</html>

因为for循环是每次遍历所有的项,因此456对应的选项卡也被设置了,为第二个滑动门的三个项添加一个函数处理就可以了,另外在鼠标移开时应该设置函数来处理背景图片的更换。
经过测试,可以达到你的效果

另外,你的三个选项卡的位置好像没摆放正确,不能放在同一排,可以设置层ctt和三个子选项卡层的宽度来解决本回答被提问者采纳
相似回答