Dynamic pagination in Jquery

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

I have this code :



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

    you can use these code for pagination if you will have wanted appending to tag in html .

    var paginationfooter = {};
    paginationfooter.Pager = function() {
        this.currentPage = 1;
        this.pagingnumber = "#pagingnum";
        this.tagg = "#matn";
        
        this.numPages = function() {
            var numPages = 0;
            if (this.paragraphs != null && this.limit != null) {
                numPages = Math.ceil(this.paragraphs.length / this.limit);
            }
         
            return numPages;
        };
        
        this.showPage = function(page) {
            this.currentPage = page;
            var html = "";
            for (var i = (page-1)*this.limit; i < ((page-1)*this.limit) + this.limit; i++) {
                if (i < this.paragraphs.length) {
                    var disply = this.paragraphs.get(i);
                    html += "<" + disply.tagName + ">" + disply.innerHTML + "";
                }
            }
            
            $(this.tagg).html(html);
            
            pagenuming(this.pagingnumber, this.currentPage, this.numPages());
        }
        
        var pagenuming = function(container, currentPage, numPages) {
    		var paging = $("");
    		
            var gridpaging = "
      "; for (var i = 1; i <= numPages; i++) { if (i != currentPage) { gridpaging += "
    • " + i + "
    • "; } else { gridpaging += "
    • " + i + "
    • "; } } gridpaging += "
    "; paging.append(gridpaging); $(container).html(paging); } } //---------------------------here input values var pager = new paginationfooter.Pager(); $(document).ready(function() { pager.limit = 5; pager.pagingtag = $('#matn'); pager.paragraphs = $('p', pager.pagingtag); pager.showPage(1); });

提交回复
热议问题