jQuery實(shí)現(xiàn)選項(xiàng)卡功能(兩種方法)
更新時(shí)間:2017年03月08日 08:48:56 作者:xiongpeiji
本文主要介紹了jQuery兩種方法寫(xiě)選項(xiàng)卡的實(shí)例,具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧
效果圖:
代碼如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="http://code.jquery.com/jquery-1.8.0.min.js"></script> <title>JQuery 源碼分析</title> <style> #div1 div{width: 200px;height: 200px;border: 1px solid #FF0000;display: none;} .active{background: red;} *{margin: 0;padding: 0;} .tab:after{content: '';display: block;clear: both;} .tab li{width: 150px;height: 30px;line-height: 30px;text-align: center;cursor: pointer;list-style: none;float: left;margin: 0 10px;background: #ABCDEF;border-radius: 5px;} .tab li.active{background: #000;color:#fff;} .content:after{content: '';display: block;clear: both;} .content li{width: 460px;height: 300px;padding:20px;background: #f7f7f7;display: none;} </style> </head> <body> <div id="div1"> <input class="active" type="button" value="1" /> <input type="button" value="2"/> <input type="button" value="3"/> <div style="display: block;">11111111111</div> <div>22222222222</div> <div>333333333333</div> </div> <ul class="tab"> <li class="active">1</li> <li>2</li> <li>3</li> </ul> <ul class="content"> <li style="display: block;">111111111111</li> <li>222222222222</li> <li>333333333333</li> </ul> <script> $(function(){ //jQuery 方法一 $('#div1').find('input').click(function(){ $('#div1').find('input').attr('class',''); $('#div1').find('div').css('display','none') $(this).attr('class','active'); $('#div1').find('div').eq($(this).index()).css('display','block'); }); //jQuery 方法二 $('.tab').find('li').click(function(){ var index = $(this).index(); $(this).addClass('active').siblings().removeClass('active'); $('.content').find('li').eq(index).show().siblings().hide(); }) }) </script> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!
您可能感興趣的文章:
- 基于jQuery實(shí)現(xiàn)選項(xiàng)卡效果
- jquery Banner輪播選項(xiàng)卡
- jQuery EasyUI Tab 選項(xiàng)卡問(wèn)題小結(jié)
- 基于jquery實(shí)現(xiàn)最簡(jiǎn)單的選項(xiàng)卡切換效果
- 基于JQuery的6個(gè)Tab選項(xiàng)卡插件
- jquery tools之tabs 選項(xiàng)卡/頁(yè)簽
- jQuery之選項(xiàng)卡的簡(jiǎn)單實(shí)現(xiàn)
- JQuery Tab選項(xiàng)卡效果代碼改進(jìn)版
- jQuery實(shí)現(xiàn)選項(xiàng)卡切換效果簡(jiǎn)單演示
相關(guān)文章
Jqgrid表格隨窗口大小改變而改變的簡(jiǎn)單實(shí)例
本篇文章主要是對(duì)Jqgrid表格隨窗口大小改變而改變的簡(jiǎn)單實(shí)例進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2013-12-12利用JQuery操作iframe父頁(yè)面、子頁(yè)面的元素和方法匯總
這篇文章主要給大家介紹了關(guān)于利用JQuery操作iframe父頁(yè)面、子頁(yè)面的元素和方法的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-09-09jQuery獲得IE版本不準(zhǔn)確webbrowser的解決方法
用$.browser.version經(jīng)常出現(xiàn)一些不準(zhǔn)確的狀況,最近碰到,做了一些總結(jié),不知道是否全面2014-02-02jquery實(shí)現(xiàn)疊層3D文字特效代碼分享
本文主要介紹了jquery實(shí)現(xiàn)疊層3D文字特效,實(shí)現(xiàn)很簡(jiǎn)單2015-08-08jQuery基于$.ajax設(shè)置移動(dòng)端click超時(shí)處理方法
這篇文章主要介紹了jQuery基于$.ajax設(shè)置移動(dòng)端click超時(shí)處理方法,分析了click事件與touchstart事件的原理與處理技巧,需要的朋友可以參考下2016-05-05jQuery+formdata實(shí)現(xiàn)上傳進(jìn)度特效遇到的問(wèn)題
這篇文章主要介紹了jQuery+formdata實(shí)現(xiàn)上傳進(jìn)度特效遇到的問(wèn)題的相關(guān)資料,需要的朋友可以參考下2016-02-02