tab 栏切换 选项卡

<style>
* {
margin: 0;
padding: 0;
}

li {
list-style-type: none;
}

.tab {
width: 978px;
margin: 100px auto;
}

.tab_list {
height: 39px;
border: 1px solid #ccc;
background-color: #f1f1f1;
}

.tab_list li {
float: left;
height: 39px;
line-height: 39px;
padding: 0 20px;
text-align: center;
cursor: pointer;
}

.tab_list .current {
background-color: #c81623;
color: #fff;
}

.item_info {
padding: 20px 0 0 20px;
}

.item {
display: none;
}
</style>

<div class="tab">         <div class="tab_list">             <ul>                 <li class="current">商品介绍</li>                 <li>规格与包装</li>                 <li>售后保障</li>                 <li>商品评价(50000)</li>                 <li>手机社区</li>             </ul>         </div>         <div class="tab_con">             <div class="item" style="display: block;">                 商品介绍模块内容             </div>             <div class="item">                 规格与包装模块内容             </div>             <div class="item">                 售后保障模块内容             </div>             <div class="item">                 商品评价(50000)模块内容             </div>             <div class="item">                 手机社区模块内容             </div>
        </div>     </div>     <script>         // 模拟京东tab栏切换 点谁谁背景色和字体颜色发生变化
        // 获取tab_list下的所有li         var tab = document.getElementsByClassName('tab_list')[0]         var lis = tab.getElementsByTagName('li')
        // 获取tab_con的所有div         var con = document.getElementsByClassName('tab_con')[0]         var dvs = con.getElementsByTagName('div')
        for (var i = 0; i < lis.length; i++) {             lis[i].setAttribute('myindex', i)             // 为每一个li绑定点击事件             lis[i].onclick = function () {                 // 点击的时候移除所有元素的class属性                 for (var j = 0; j < lis.length; j++) {                     // 把className 置为空                     lis[j].className = ''                 }                 // 为当前点击元素添加class                 this.className = 'current'                 // 点击的时候切换下面的div                 // 干掉其它div                 for (var i = 0; i < dvs.length; i++) {                     dvs[i].style.display = 'none'                 }                 // 获取点击的li设置的自定义属性myindex                 var index = this.getAttribute('myindex')                 // console.log(index);                 // 让下标和点击的li下标相同的元素显示即可                 dvs[index].style.display = 'block'             }         }
    </script>
上一篇:Windows文件句柄无效


下一篇:JDBC-SQLserver