<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>tab栏切换效果</title>
<style media="screen">
*{
margin: 0;
padding: 0;
border: 0 none;
outline: none;
}
#btns{
width: 300px;
margin: 100px auto;
}
#btns button {
width: 60px;
height: 30px;
float: left;
border-right: 1px solid #ccc;
}
.color{
background-color: #eb923f;
}
</style>
<script type="text/javascript">
window.onload = function () {
var btns = document.getElementById("btns").getElementsByTagName("button");
for (var i = 0; i < btns.length; i++) {
btns[i].onclick = function () {
for (var j = 0; j < btns.length; j++) {
//把所有的button清空类名
btns[j].className = "";
}
//点击的那个盒子添加指定类名
this.className = "color";
}
}
}
</script>
</head>
<body>
<div id="btns">
<button class="color">按钮1</button>
<button>按钮2</button>
<button>按钮3</button>
<button>按钮4</button>
<button>按钮5</button>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>tab栏切换效果</title>
<style media="screen">
*{
margin: 0;
padding: 0;
border: 0 none;
outline: none;
}
.baohan{
width: 300px;
margin: 100px auto;
border: 1px solid #ccc;
}
#btns button {
width: 60px;
height: 30px;
float: left;
border-right: 1px solid #ccc;
}
#divs div {
width: 300px;
height: 100px;
font-size: 60px;
padding-top: 60px;
background-color: #eb923f;
text-align: center;
display: none;
}
.color{
background-color: #eb923f;
}
</style>
<script type="text/javascript">
window.onload = function () {
var btns = document.getElementById("btns").getElementsByTagName("button");
var divs = document.getElementById("divs").getElementsByTagName("div");
for (var i = 0; i < btns.length; i++) {
btns[i].index = i; //自定义属性,用于关联下面的大盒子
btns[i].onclick = function () {
for (var j = 0; j < btns.length; j++) {
//把所有的button清空类名
btns[j].className = "";
}
//点击的那个盒子添加指定类名
this.className = "color";
for (var i = 0; i < divs.length; i++) {
//先让底下的div全部隐藏
divs[i].style.display = "none";
}
//然后给当前所点击按钮相关联的盒子添加指定属性
divs[this.index].style.display = "block";
}
}
}
</script>
</head>
<body>
<div class="baohan">
<div id="btns">
<button class="color">按钮1</button>
<button>按钮2</button>
<button>按钮3</button>
<button>按钮4</button>
<button>按钮5</button>
</div>
<div id="divs">
<div style="display:block;">1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
</div>
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有