2014-12-28 82 views
-1

我發現nice solution here「加載更多...」鏈接。如何在本例中更改「加載更多」按鈕

在參考答案中,有一個JSFidlle example。如果沒有隱藏的div,我怎樣才能將文本「加載更多」更改爲「不再更多div」?此時我有一個提醒,但我更願意將文字「加載更多」更改爲「不再更多div」。

我此刻代碼:

$(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 
     } 
    }); 
}); 

回答

2

根據你的要求,該鏈接將簡單地使用下面的代碼更改爲「沒有更多的div」:

$(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 
      $("#load").text("No more divs"); // change the text of the link to "No more divs" 
     } 
    }); 
}); 
+0

你搖滾我的朋友 – kodjoe

+0

只是一個問題先生,如果沒有可點擊的鏈接,我們可以「沒有更多的div」嗎? – kodjoe