2016-01-28 99 views
0

我想在博客頁面上添加一個「加載更多」按鈕。我發現this exemple。但我不知道在博客(HTML/CSS/JavaScript)上放置代碼的每個部分的位置,尤其是這個jQuery部分碼。如何在博客上添加「加載更多」按鈕?

$(function(){ 
    $("div").slice(0, 10).show(); // select the first ten 
    $("#load").click(function(e){ // click event for load more 
     e.preventDefault(); 
     $("div:hidden").slice(0, 10).show(); // select next 10 hidden divs and show them 
     if($("div:hidden").length == 0){ // check if any hidden divs still exist 
      alert("No more divs"); // alert if there are none left 
     } 
    }); 
}); 
+0

所提供的例子,在一次加載所有內容,並將其顯示在一個時間十個項目。我懷疑這是你想要的效果,我想你可能想要使用Ajax實時加載帖子。 –

+0

感謝您的評論。其實,這就是我想要做的,我不想一次顯示所有的內容,以避免長頁面,我想創建一個按鈕,每次你打它時顯示更多的內容,我想在特定頁面上執行,而不是在帖子的主頁上。 –

回答

1

我已經找到了解決辦法,這個代碼是什麼我正在尋求

<div>content content content content content content content content content content content content content content content.<a href="javascript:void(0);" onclick="jQuery('.show-more-toggle').toggle();" class="show-more-toggle v5-dark-link">show more</a><span class="show-more-toggle" style="display: none">more more more more more more more more more more more more more more more more more </span></div>