利用js實現選項卡的特別效果的執行個體_javascript技巧

來源:互聯網
上載者:User

複製代碼 代碼如下:

<html>
<head>
    <meta charset="utf-8"/>
    <style type="text/css">
        *{margin:0;padding:0;border:0}
        #main{width:300px;height:300px;background-color:green}
        #head{height:50px;background-color:red}
        #head li{float:left;list-style:none;height:50px;width:72px;text-align:center;line-height:50px;background-color:orange;margin-right:3px}
    </style>
</head>
<body>
    <div id="main">
    <div id="head">
    <ul>
        <li id="tab1" onclick="show(1)" style="background-color:green">新聞</li>
        <li id="tab2" onclick="show(2)">體育</li>
        <li id="tab3" onclick="show(3)">音樂</li>
        <li id="tab4" onclick="show(4)">娛樂</li>
    </ul>
    </div>
    <div id="content">
    <p id="p1">今天習總書記去烏幹達訪問了</p>
    <p id="p2" style="display:none">喬丹改打乒乓球了</p>
    <p id="p3" style="display:none">江南style</p>
    <p id="p4" style="display:none">趙本山退出春晚</p>
    </div>
    </div>
</body>
    <script>
        function show(n){
            for(var i=1;i<=4;i++){
            //先把所有的選項卡背景顏色設為橙色,內容都隱藏
                document.getElementById("tab"+i).style.backgroundColor = 'orange';
                document.getElementById("p"+i).style.display = 'none';
            }
                document.getElementById("tab"+n).style.backgroundColor = 'green';
                document.getElementById("p"+n).style.display = "block";
        }

    </script>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.