本篇內容介紹了“jQuery怎么實現選項卡功能”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
效果圖:

代碼如下:
<!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 >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 >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>“jQuery怎么實現選項卡功能”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。