我在頁面上有四個「.content」部分。我想要切換每個部分,但還要顯示所有部分以顯示所有「.content」。當我嘗試添加一個全部顯示按鈕時,切換將停止工作。仍然習慣jQuery,任何幫助將不勝感激!顯示所有部分在jQuery中切換
這裏是HTML的結構:
<div class="row add-top">
<div class="span4">
<p class="expand"><a href="#">Show All</a></p>
<p class="contract"><a href="#">Hide All</a></p>
<p class="heading"><strong>Week 01 - Welcome!</strong></p><!-- WEEK -->
<section class="content">
<p></p>
</section>
</div>
$(document).ready(function() {
$(".content").hide();
//toggle the componenet with class msg_body
$(".heading").click(function() {
$(this).next(".content").slideToggle(500);
$(".content").hide();
//toggle the componenet with class msg_body
$(".expand").click(function() {
$(this).next(".content").slideToggle(500);
$(".content").hide();
//toggle the componenet with class msg_body
$(".contract").click(function() {
$(this).next(".content").slideToggle(500);
});
})
});
}
可以分享你的HTML樣本 –
什麼'expand'和'contract'元素 –
'expand'和'contract'將顯示所有四個內容部分一次 – user3188960