jQuery實(shí)現(xiàn)選項(xiàng)卡功能(兩種方法)
更新時(shí)間:2017年03月08日 08:48:56 作者:xiongpeiji
本文主要介紹了jQuery兩種方法寫選項(xiàng)卡的實(shí)例,具有很好的參考價(jià)值。下面跟著小編一起來看下吧
效果圖:
代碼如下:
<!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>
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!
您可能感興趣的文章:
相關(guān)文章
利用JQuery操作iframe父頁面、子頁面的元素和方法匯總
這篇文章主要給大家介紹了關(guān)于利用JQuery操作iframe父頁面、子頁面的元素和方法的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(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)很簡單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)度特效遇到的問題
這篇文章主要介紹了jQuery+formdata實(shí)現(xiàn)上傳進(jìn)度特效遇到的問題的相關(guān)資料,需要的朋友可以參考下2016-02-02