我有一個ul,我只想顯示最初的5個項目。當用戶點擊顯示更多時,顯示其他項目並且鏈接詞彙表更改。然後,當用戶再次點擊時,它會有相反的操作。jquery顯示更多無序列表不起作用
<ul class="section-titles">
<li>Section 01 Title <span>0:00</span> </li>
<li>Section 02 Title <span>0:00</span> </li>
<li>Section 03 Title <span>0:00</span> </li>
<li>Section 04 Title <span>0:00</span> </li>
<li>Section 05 Title <span>0:00</span> </li>
<li>Section 06 Title <span>0:00</span> </li>
<li>Section 07 Title <span>0:00</span> </li>
<li>Section 08 Title <span>0:00</span> </li>
<li>Section 09 Title <span>0:00</span> </li>
<li>Section 10 Title <span>0:00</span> </li>
</ul>
<div class="show-more">Show more</div>
$(".show-more").click(function() {
var n = $(".show-more").html;
if (n = 'Show less') {
$('.section-titles li:nth-child(n+6)').css('display', 'hidden');
$('.show-more').html('Show more')
} else {
$('.section-titles li:nth-child(n+6)').css('display', 'block');
$('.show-more').html('Show less')
}
});
請告訴我問題嗎? – Andrew
問題是什麼?也許提供HTML –
你能舉個例子嗎? – Adjit