Dynamic pagination in Jquery

前端 未结 7 2170
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-06 10:59

I have this code :



        
7条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-06 11:13

    //Pagination
    pageSize = 8;
    
    showPage = function(page) {
      $('.line-content').hide();
      $('.line-content:gt('+((page-1)*pageSize)+'):lt('+(page)*(pageSize-1)+')').show();
       $('.line-content:eq('+((page-1)*pageSize)+')').show();
    }
    
    var pgs = Math.ceil($('.line-content').length/pageSize);
    var pgnt = '';
      for(var i=1;i<=pgs;i++){
    	pgnt += '
  • '+i+'
  • '; } $('#pagin').html(pgnt); $("#pagin li a").click(function() { $("#pagin li a").removeClass("current"); $(this).addClass("current"); showPage(parseInt($(this).text())) }); showPage(1);
    .current {
      color: green;
    }
    
    #pagin li {
      display: inline-block;
    }
    
    
    1 I have some content
    2 I have some content
    3 I have some content
    4 I have some content
    5 I have some content
    6 I have some content
    7 I have some content
    8 I have some content
    9 I have some content
    10 I have some content
    11 I have some content
    12 I have some content

    This is inline to what you needed.

提交回复
热议问题