2014-07-10 122 views
1
$('a.prev, a.next').click(function(){ 
var a = $(this), 
    current = $('#pagin li a.current'), 
    page = parseInt(current.text()); 
if (a.hasClass('prev')) { 
    page--; 
    if (page < 1) page = 1; 
} else if (a.hasClass('next')) { 
    page++; 
    if (page > pageCount) page = pageCount; 
} 
$('.page:eq(' + (page - 1) + ')').click(); 
}); 

這不行。請幫助我..分頁/上一頁和下一頁鏈接不顯示

如何在此代碼中添加下一個和上一個按鈕。

請參閱的js小提琴鏈接:http://jsfiddle.net/jfm9y/609/

+0

'頁頁次不defined' –

+0

'.page'不上你的小提琴存在,不在於它的核心問題 – Huangism

回答

0

你需要申報內容頁頁次。

工作例如:http://jsfiddle.net/jfm9y/611/

pageSize = 1; 
pageCount = $(".content").length; 

showPage = function(page) { 
    $(".content").hide(); 
    $(".content").each(function(n) { 
     if (n >= pageSize * (page - 1) && n < pageSize * page) 
      $(this).show(); 
    });   
} 

showPage(1); 

$("#pagin li a").click(function() { 
    $("#pagin li a").removeClass("current"); 
    $(this).addClass("current"); 
    showPage(parseInt($(this).text())) 
}); 
    $('a.prev, a.next').click(function(){ 
    var a = $(this), 
     current = $('#pagin li a.current'), 
     page = parseInt(current.text()); 
     console.log(page); 
    if (a.hasClass('prev')) { 
     page--; 
     if (page < 1) page = 1; 
    } else if (a.hasClass('next')) { 
     page++; 
     if (page > pageCount) page = pageCount; 
    } 

    $($('#pagin li a')[page- 1]).click(); 
}); 
+0

太謝謝你了... – SekDinesh

相關問題