jQuery寫選項卡

來源:互聯網
上載者:User

標籤:第一個   pointer   java   cti   選項   hover   狀態   splay   on()   

<!DOCTYPE html>

<htmllang="en">

<head>

<metacharset="UTF-8"><title>choseCart</title>

<script src="https://cdn.bootcss.com/jquery/1.8.3/jquery.js"></script>

<styletype="text/css">

*{margin: 0;padding: 0;}

li{list-style: none;}

#menu {height: 30px;}

#menu li{float: left;background: #999;color: #fff;cursor: pointer;border:2px solid #666;}

#menu .active{border-right-color: #666;border-left-color: #666;border-top-color: blue;border-bottom-color: #fff}

#pannel div:nth-of-type(1){background: green;width: 335px;height: 200px;}

#pannel div:nth-of-type(2){background: blue;width: 335px;height: 200px;}

#pannel div:nth-of-type(3){background: black;width: 335px;height: 200px;}

#pannel div:nth-of-type(4){background: red;width: 335px;height: 200px;}

#pannel div{display: none;}

#pannel .active{display: block;}

</style><scripttype="text/javascript">

$(function(){

let oLi=$(‘#menu li‘);

/*oLi.bind(‘click‘,function() {

let iIndex=$(this).index();oLi.removeClass(‘active‘).eq(iIndex).addClass(‘active‘);

$(‘#pannel div‘).removeClass(‘active‘).eq(iIndex).addClass(‘active‘);

});*/

oLi.hover(function(){

let iIndex=$(this).index();

oLi.removeClass(‘active‘).eq(iIndex).addClass(‘active‘);

$(‘#pannel div‘).removeClass(‘active‘).eq(iIndex).addClass(‘active‘);

})

})

</script>

</head>

<body>

<divid="box">

<ulid="menu">

<liclass="active">第一個按鈕</li>

<li>第二個按鈕</li>

<li>第三個按鈕</li>

<li>第四個按鈕</li>

</ul>

<divid="pannel">

<divclass="active"></div>

<div></div>

<div></div>

<div></div>

</div></div>

</body>

</html>

回來再總結下思路吧:

1:CSS布局要點:預設按鈕和內容地區第一個為active狀態,

2:寫jQuery時通過addClass()/removeClass()來改變卡片的狀態;

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.