在此代碼中,我想顯示show more
鏈接,3個按鈕之後: 我知道,如何在x詞後顯示更多按鈕,但如何顯示更多鏈接按鈕後?如何在3個按鈕後顯示「更多閱讀」鏈接
這是我的代碼顯示在x話show more
鏈接,如果它可以幫助:
jQuery(function(){
var minimized_elements = $('span.showmore');
minimized_elements.each(function(){
var t = $(this).text();
if(t.length < 410) return;
$(this).html(
t.slice(0,410)+'<span>... </span><a href="" class="more">Show More</a>'+
'<span style="display:none;">'+ t.slice(410,t.length)+' <a href="#" class="less">Less</a></span>'
);
});
$('a.more', minimized_elements).click(function(event){
event.preventDefault();
$(this).hide().prev().hide();
$(this).next().show();
});
$('a.less', minimized_elements).click(function(event){
event.preventDefault();
$(this).parent().hide().prev().show().prev().show();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="playtrailer">Trailer 1</button>
<button class="playtrailer">Trailer 2</button>
<button class="playtrailer">Trailer 3 HD</button>
<button class="playtrailer">Trailer 4 SD</button>
<button class="playtrailer">Trailer 5</button>
<button class="playtrailer">Trailer 6</button>
<button class="playtrailer">Video</button>
您當前的代碼假設你正在處理的只有文字。相反,可以考慮像'var t = $(this).children();' - 這應該給你一個按鈕的集合。您需要使用稍微更高級的DOM創建方法,而不是構建HTML,但「slice」對於獲取按鈕的子集仍然可以正常工作。 –
你想在每三次或僅一次後顯示更多按鈕嗎? –
只有1次@ Mr.Developer – Toby