DIV+CSS 樣式簡單布局Tab 切換

來源:互聯網
上載者:User

標籤:style   class   blog   code   java   http   

<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title>    <script src="../JS/JQuery/jquery-1.9.1.js" type="text/javascript"></script>    <style type="text/css">        .content        {            margin: 50px;            border: 8px;            width: auto;            height: auto;        }        .title        {            height: 20px;            width: auto;        }        .common        {            width: 20%;            float: left;            font-size: 20px;            color: Black;            background-color: #E0E0E0;        }        .selected        {            background-color: #EEE;        }        .contentBody        {            width: auto;            height: 500px;        }        .contendiv        {            padding: 20px;            width: 97%;            height: 500px;            float: left;            background-color: #EEE;        }        .divHidden        {            display: none;        }    </style>    <script type="text/javascript">        $(function() {            $(".common").click(function() {                var divId = $(this).attr("id");                //alert(divId);                if (jQuery(this).attr("class").indexOf("selected") > 0) {                    //jQuery(this).removeClass("selected")                } else {                    $("div").removeClass("selected");                    jQuery(this).addClass("selected");                }                                //var list = $(".contendiv");                $(".contendiv").addClass("divHidden");                $("#div" + divId).removeClass("divHidden");            });        });    </script></head><body>    <form id="form1" runat="server">    <div>        <div class="content">            <div class="title">                <div id="1" class="common selected">                    Tab1                </div>                <div id="2" class="common">                    Tab2                </div>                <div id="3" class="common">                    Tab3                </div>            </div>            <div class="contentBody">                <div id="div1" class="contendiv">                    我是tab1                </div>                <div id="div2" class="contendiv divHidden">                    我是tab2                </div>                <div id="div3" class="contendiv divHidden">                    我是tab3                </div>            </div>        </div>    </div>    </form></body></html>


這個是一個最簡單最原始的基本Tab切換的樣子。很簡單,剛學習樣式布局JQuery的同學可以參考。大牛就不要拍磚了。

只要控制好頭部的DIV的點擊事件就OK了,下面對應的三個DIV的相對應切換隱藏。So Easy!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.