JS制作tab选项卡

先看效果图,比较简陋,意思下的哈

下面是代码

<!DOCTYPE>
<html>
<meta charset="UTF-8">
<title></title>
<head>
<style type="text/css">
#div1 a{
	padding: 0 5px;
	color: black;
	text-decoration: none;
	border: #ccc solid 1px;
}
#div1 .active{
	color: white;
	background: red;
}
#div1 div{

	width: 200px;
	height: 200px;
	background: #ccc;
	border: black solid 1px;
	display: none;
}
</style>
<script type="text/javascript">
window.onload=function ()
{
	var oDiv=document.getElementById("div1");
	var aBtn=oDiv.getElementsByTagName("a");
	var aDiv=oDiv.getElementsByTagName("div");
	
	for (var i=0;i<aBtn.length;i++)
	{
		aBtn[i].index=i;
		aBtn[i].onmouseover=function ()
		{
			for (var i=0;i<aBtn.length;i++)
			{
				aBtn[i].className="";
				aDiv[i].style.display="none";
			};
			this.className="active";
			aDiv[this.index].style.display="block";
		};
	};	
};
</script>
</head>
<body>

<div id="div1">
	<a class="active" href="javasript:;">教育</a>
	<a href="javasript:;">培育</a>
	<a href="javasript:;">招生</a>
	<a href="javasript:;">出国</a>
	<div style="display:block;">
		教育教育教育教育教育教育教育
	</div>
	<div>
		培育培育培育培育培育培育培育培育培育
	</div>
	<div>
		招生招生招生招生
	</div>
	<div>
		出国出国出国出国出国出国出国出国出国出国出国出国
	</div>
</div>
</body>

</html>

一款经典简洁的javascript+css Tab转换特效代码

<!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:936px;/*滑动门的宽度*/}
/* TAB 切换效果 */
.tb_{background-image: url(‘http://websky18.com/d/file/mimg/tabs1.gif’); background-repeat: repeat-x;background-color: #E6F2FF;}
.tb_ ul{height:24px;}
.tb_ li{float:left;height: 24px;line-height:1.9;width: 94px;cursor:pointer;}
/* 控制显示与隐藏css类 */
.normaltab   { background-image:url(‘http://websky18.com/d/file/mimg/tabs2.gif’); background-repeat: no-repeat; color:#1F3A87 ;}
.hovertab    { background-image: url(‘http://websky18.com/d/file/mimg/tabs3.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 >
<div id=”tb_”>
<ul>
<li id=”tb_1″ onmouseover=”x:HoverLi(1);”>
ASP.NET</li>
<li id=”tb_2″ onmouseover=”i:HoverLi(2);”>
MYSQL</li>
<li id=”tb_3″ onmouseover=”a:HoverLi(3);”>
DELPHI</li>
<li id=”tb_4″ onmouseover=”o:HoverLi(4);”>
VB.NET</li>
<li id=”tb_5″ onmouseover=”g:HoverLi(5);”>
JAVA</li>
<li id=”tb_6″ onmouseover=”z:HoverLi(6);”>
PHP5</li>
</ul>
</div>
<div >
<div id=”tbc_01″>这里是ASP.NET的相关内容</div>
<div id=”tbc_02″>这里是MYSQL的相关内容</div>
<div id=”tbc_03″>这里是DELPHI的相关内容</div>
<div id=”tbc_04″>这里是VB.NET的相关内容</div>
<div id=”tbc_05″>这里是JAVA的相关内容</div>
<div id=”tbc_06″>这里是PHP5的相关内容</b>
</div>
</div>
</div>
</body>
</html>