标签:
<!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=utf-8" />
<title>选项卡(初级)</title>
<style>
#div button{height:30px; width:60px;}
#div div{ display:none;}
#div1{ height:400px; width:300px; background-color:#C00; border:1px solid #000;}
#div2{ height:400px; width:300px; background-color:#3F3; border:1px solid #000;}
#div3{ height:400px; width:300px; background-color:#CF3; border:1px solid #000;}
#div4{ height:400px; width:300px; background-color:#30C; border:1px solid #000;}
.active{ background-color:#F6F;}
</style>
<script>
window.onload=function(){
var di=document.getElementById(‘div‘);
var btn=di.getElementsByTagName(‘button‘);
var d=di.getElementsByTagName(‘div‘);
for( var i=0; i<btn.length; i++){
btn[i].index=i;
btn[i].onclick=function(){
for( var i=0; i<btn.length; i++){
btn[i].className="";
d[i].style.display=‘none‘;
}
this.className=‘active‘;
d[this.index].style.display=‘block‘
}
}
}
</script>
</head>
<body>
<div id="div">
<button class="active">红</button>
<button>绿</button>
<button>黄</button>
<button>蓝</button>
<div id="div1" style="display:block"></div>
<div id="div2"></div>
<div id="div3"></div>
<div id="div4"></div>
</div>
</body>
</html>
标签:
原文地址:http://www.cnblogs.com/wswbk/p/4658279.html