zoukankan      html  css  js  c++  java
  • 面向对象写tab选项卡

    <!DOCTYPE html>
    <html>
    <head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
    *{
    margin: 0;
    padding: 0;
    }
    #div1 input{background-color: #ccc}
    #div1 .active{background-color: #ffff00}
    #div1 div{ 200px;height: 200px;background-color: #cccccc;display: none}
    </style>


    //js代码:

    <script>
    window.onload = function(){
    var oDiv = document.getElementById("div1");
    var tab = new Tab(oDiv);
    tab.init();
    }
    function Tab(id){
    this.aBtn=id.getElementsByTagName("input")
    this.aDiv=id.getElementsByTagName("div")
    }
    Tab.prototype.init = function(){
    var obj =this;//tab实例化对象
    for(var i=0;i<obj.aBtn.length;i++){
    obj.aBtn[i].index = i;//给li添加一个索引
    obj.aBtn[i].onclick=function(){
    obj.fnClick(this);//this当前点击的元素li
    }

    }
    }
    Tab.prototype.fnClick=function(aBtn){
    //alert(this); //li
    for (var i =0;i<this.aBtn.length;i++)
    {
    this.aBtn[i].className = "";
    this.aDiv[i].style.display = "none";
    }
    aBtn.className = "active";
    this.aDiv[aBtn.index].style.display = "block";
    };
    </script>

    </head>



    <body>
    <div id="div1">
    <input type="button" value="时尚">
    <input type="button" value="体育">
    <input type="button" value="财经">
    <div style="display: block">时尚内容</div>
    <div>体育内容</div>
    <div>财经内容</div>
    </div>

    </body>
    </html>


    效果:

  • 相关阅读:
    Qt 主窗口与子窗口之间传值
    Qt 如何使窗体初始最大化
    C++ strcmp与strncmp的比较
    Qt 状态栏(statusbar)的使用
    C++中的补零
    Qt QString转char[]数组
    PAT基础6-9
    PAT基础6-8
    PAT基础6-6
    PAT基础6-7
  • 原文地址:https://www.cnblogs.com/mylove0/p/7459047.html
Copyright © 2011-2022 走看看