jquery製作選項卡

來源:互聯網
上載者:User

標籤:

思路:點擊按鈕後,先讓所有的按鈕的class屬性都為“”,所有的div的display樣式都為none;再讓當前被點擊按鈕的class屬性為active,以及所對應的div的display樣式為block。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<style>
#nav button{width:200px;height:50px;}
#nav .active{background:yellow;}
.news{width:600px;height:600px;}
.a{display:block;background:pink;}
.b{display:none;background:blue;}
.c{display:none;background:green;}
</style>
<title>jquery製作選項卡</title>
<script src="jquery.min.js"></script>
<script>
$(function(){
  $("#nav").find("button").click(function(){
    $("#nav").find("button").attr("class","");
    $("#news").find(".news").css("display","none");

    $(this).attr("class","active");
    $("#news").find(".news").eq($(this).index()).css("display","block");
  });
});
</script>
</head>
<body>
<div id="nav">
<button class="active">新聞動態</button>
<button>專題製作</button>
<button>圖片欣賞</button>
</div>
<div id="news">
<div class="news a">aaa</div>
<div class="news b">bbb</div>
<div class="news c">ccc</div>
</div>
</body>
</html>

jquery製作選項卡

聯繫我們

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