<!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 type="text/css">
#tab{width:300px;border:3px solid #CCC;}
#tab .active{background-color:#FFF}
#tab h3{
margin:0px;
padding:0px;
font-size:14px;
float:left;
background-color:#CCC;
width:60px;
height:24px;
line-height:24px;
text-align:center;
}
#tab div{
clear:both;
height:100px;
font-size:14px;
padding:20px 0px 0px 20px;
display:none;
}
</style>
<script>
window.onload=function(){
var oTab=document.getElementById("tab");
var aH3=oTab.getElementsByTagName("h3");
var aDiv=oTab.getElementsByTagName("div");
for(var i=0;i<aH3.length;i++){
aH3[i].index=i;
aH3[i].onclick=function(){
for(var i=0;i<aH3.length;i++){
aH3[i].className="";
aDiv[i].style.display="none";
}
this.className="active";
aDiv[this.index].style.display="block";
}
}
}
</script>
</head>
<body>
<div id="tab">
<h3 class="active">教育</h3>
<h3>娱乐</h3>
<h3>汽车</h3>
<div style="display:block">教育的内容</div>
<div>娱乐的内容</div>
<div>汽车的内容</div>
</body>
</html>
选项卡切换
最新推荐文章于 2022-06-27 21:18:20 发布