• js 实现简单的选项卡


    <!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=gb2312" />
    <title>无标题文档</title>
    <style>
        body,ul{margin:0;padding:0;}
        li{list-style:none;}
        #tab{width:216px;margin:30px auto;}
        #tab ul{width:216px;height:32px;}
        #tab li{float:left;width:60px;height:24px;text-align:center;font-size:14px;line-height:24px;margin-left:10px;border:1px solid #000;background:#CCCCCC}
        #tab .active{background:#FFFF00;}
        #tab div{width:224px;height:200px;background:#CCCCCC;display:none;}
        #tab .show{display:block;}
    </style>
    <script>
        window.onload =function(){
            var oDiv = document.getElementById('tab');
            var aLi = oDiv.getElementsByTagName('li');
            var aDiv = oDiv.getElementsByTagName('div');
            var lastIndex = 1;
            for(var i=0;i<aLi.length;i++){
                aLi[i].index = i;
                aLi[i].onclick = function(){
                    
                    /*方法-
                    for(var j=0;j<aLi.length;j++){
                        aLi[j].className = '';
                        aDiv[j].style.display = 'none';
                    }
                    */
                    /*方法二*/
                    
                    aLi[lastIndex].className = '';
                    aDiv[lastIndex].style.display = 'none';
                    
                    this.className  = 'active';
                    aDiv[this.index].style.display = 'block';
                    lastIndex = this.index;
                };
            }
        };
    </script>
    </head>
    
    <body>
    <div id='tab'>
        <ul>
            <li>port端口</li>
            <li class='active'>静态Mac</li>
            <li>vlan列表</li>
        </ul>
    
        <div class='hide'>interface gig1/1/1</div>
        <div class='show'>mac 0001.0002.0004</div>
        <div class='hide'>vlan 1 2 3</div>
    </div>
    </body>
    </html>
  • 相关阅读:
    vue 样式使用总结
    安卓内嵌H5只展示部分静态页面
    Excel 2016入门与提高
    Oracle Exadata技术详解
    计算机网络基础
    Photoshop扁平化平面设计手册
    C程序设计伴侣——帮你更好地理解谭浩强老师的那本书以及更多!
    中文版Project 2007实用教程
    新手学CorelDRAW X8商业设计200+
    Altium Designer 17电路设计与仿真从入门到精通
  • 原文地址:https://www.cnblogs.com/moon-yyl/p/9034988.html
Copyright © 2020-2023  润新知