【www.bbyears.com--js教程】
实现思路:
1、首先获取id元素。
2、for循环历遍按钮元素添加onclick事件。
3、排他思想,点击按钮时设置所有选项卡按钮样式为空,利用this关键字指定当前选项卡获得高亮样式。
4、下面的多个div内容块以此类推。
源代码:
代码如下
* {
margin: 0;
padding: 0;
}
.box {
width: 278px;
margin: 0 auto;
margin-top: 100px;
background-color: #F7F7F8;
overflow: hidden;
}
.btn button {
outline:none;
color: #616161;
font:14px/100% arial,"Hiragino Sans GB","Hiragino Sans GB W3",\5b8b\4f53;
border: none;
height: 34px;
width: 51px;
background-color: #F7F7F8;
float: left;
cursor: pointer;
}
.box .btn i {
height: 16px;
border-left: 1px solid #EAEAEA;
margin-top: 9px;
float: left;
_font-size: 0px;
}
.box .btn button:hover {
color: #0AA770;
}
.box .btn s {
cursor: pointer;
text-decoration: none;
font:14px/34px arial,"Hiragino Sans GB","Hiragino Sans GB W3",\5b8b\4f53;
}
#box1 #btns .clickbtn {
border-top: 1px solid #0AA770;
color: #0AA770;
}
.bottom {
display: none;
position: absolute;
width: 278px;
height: 110px;
color: #fff;
text-align: center;
font:14px/100% arial,"Hiragino Sans GB","Hiragino Sans GB W3",\5b8b\4f53;
}
.bottom a {
color: #fff;
position: relative;
top: -20px;
left: 0px;
text-decoration: none;
}
.bottom a:hover {
text-decoration: underline;
}
<script>
window.onload = function(){
var btns = document.getElementById("btns").getElementsByTagName("button");
var divs = document.getElementById("bottomdivs").getElementsByTagName("div");
btns[0].className = "clickbtn";
for(var i = 0;i btns[i].index= i; btns[i].onclick=function(){ //alert(this.index); for(varj=0;j btns[j].className=""; } this.className="clickbtn"; for(varb=0;b divs[b].style.display="none"; } divs[this.index].style.display="block"; } } } </script> +小伙直播时遭遇“闹鬼”事件 全过程被拍下
男子穿新郎装背充气娃娃游街
她满足所有人对才女的幻想
王毅回应中美是否会在南海发生冲突
刘翔与娇妻秀恩爱 豪车曝光车牌太抢眼