面向对象版选项卡

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
*{
padding:0;
margin:0;
list-style: none;
}
#box1,#box2,#box3{
width:500px;
height:500px;
border:1px solid red;
}
#box1 input,#box2 input,#box3 input{
background: yellow;
}
#box1 .active,#box2 .active,#box3 .active{
background: red;
}
#box1 div,#box2 div,#box3 div{
width:300px;
height:300px;
background: red;
font-size: 50px;
text-align: center;
line-height: 300px;
display: none;
}
#box1 .show,#box2 .show,#box3 .show{
display: block;
}
</style>
</head>
<body>
<div id="box1">
<input type="button" value="按钮1" class="active">
<input type="button" value="按钮2">
<input type="button" value="按钮3">
<div class="show">1</div>
<div>2</div>
<div>3</div>
</div>
<div id="box2">
<input type="button" value="按钮1" class="active">
<input type="button" value="按钮2">
<input type="button" value="按钮3">
<input type="button" value="按钮4">
<input type="button" value="按钮5">
<div class="show">1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
<div id="box3">
<input type="button" value="按钮1" class="active">
<input type="button" value="按钮2">
<input type="button" value="按钮3">
<input type="button" value="按钮4">
<input type="button" value="按钮5">
<input type="button" value="按钮6">
<input type="button" value="按钮7">
<div class="show">1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
</div>
<script>
function tab(id) {
var _this = this;
this.oBox = document.getElementById(id);
this.aBtn = this.oBox.getElementsByTagName('input');
this.aBox = this.oBox.getElementsByTagName('div');
for (var i=0; i<this.aBtn.length; i++) {
this.aBtn[i].index = i;
this.aBtn[i].onclick = function () {
_this.fnClick(this)
}
}
tab.prototype.fnClick = function (oBtn) {
for (var i=0; i<this.aBtn.length; i++) {
this.aBtn[i].className = '';
this.aBox[i].className = '';
}
this.aBox[oBtn.index].className = 'show';
oBtn.className = 'active';
}
}
new tab('box1');
new tab('box2');
new tab('box3');
</script>
</body>
</html>

转载于:https://www.cnblogs.com/qiudongjie/p/6602716.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值