<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
#content_main_top{
height: 80px;
line-height: 80px;
text-align: center;
border-bottom:1px solid #888888;
}
#content_main_top input{
padding:10px 15px;
margin-left: 5px;
background-color: #2B2B2B;
color: #FFFFFF;
outline: none;
border:none;
}
ul{
list-style: none;
}
li{
float:left;
padding:30px 40px;
}
img{
200px;
height:150px;
}
.show{display: block;}
.hide{display: none;}
</style>
</head>
<body>
<div id="content_main_top">
<input type="button" name="btn" class="btn1" value="全部" />
<input type="button" name="btn" class="btn2" value="建站案例" />
<input type="button" name="btn" class="btn3" value="应用案例" />
<input type="button" name="btn" class="btn4" value="运维案例" />
<ul>
<li><img src="img/33.jpg"/></li>
<li><img src="img/img/12.jpg"/></li>
<li><img src="img/img/25.jpg"/></li>
<li><img src="img/img/39.jpg"/></li>
</ul>
<ul class="hide">
<li><img src="img/33.jpg"/></li>
<li><img src="img/img/12.jpg"/></li>
</ul>
<ul class="hide">
<li><img src="img/33.jpg"/></li>
<li><img src="img/img/12.jpg"/></li>
<li><img src="img/img/39.jpg"/></li>
</ul>
<ul class="hide">
<li><img src="img/33.jpg"/></li>
</ul>
</div>
<script type="text/javascript">
//方法一:面向过程的选项卡
/* window.onload=function (){
var Abtn=document.getElementById("content_main_top");
var Bbtn=Abtn.getElementsByTagName("input");
var imgboxlist=Abtn.getElementsByTagName("ul");
for(var i=0;i<Bbtn.length;i++){
Bbtn[i].index=i;
Bbtn[i].onclick=function(){
for(var j = 0; j< imgboxlist.length; j++) {
imgboxlist[j].className = "hide";
}
imgboxlist[this.index].className = "show";
}
}
}*/
// 方法二:面向对象的选项卡,实现对代码的可复用性
function TabSwitch(id){
var _this=this;
var Abtn=document.getElementById(id);
this.Bbtn=Abtn.getElementsByTagName("input");
this.imgboxlist=Abtn.getElementsByTagName("ul");
for(var i=0;i<this.Bbtn.length;i++){
this.Bbtn[i].index=i;
this.Bbtn[i].onclick=function(){
_this.fnclick(this);
};
}
}
TabSwitch.prototype.fnclick=function(oo){
// alert(this);
for(var j = 0; j<this.imgboxlist.length; j++) {
this.imgboxlist[j].className = "hide";
}
this.imgboxlist[oo.index].className = "show";
}
new TabSwitch("content_main_top");
</script>
</body>
</html>