JQuery的分页插件pagination.js

Posted zhoupan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JQuery的分页插件pagination.js相关的知识,希望对你有一定的参考价值。

在页面分页的方法:

  ajax从后台获取数据后在前台进行分页

      

$.ajax({
            type: "POST",
            url: API_CONFIG.getNews,
            data: JSON.stringify(params),
            dataType: "json",
            contentType: ‘application/json;charset=UTF-8‘,
            success: function(data) {
                if(data != null) {
                    if(data.STATUS == true) {
                        var newsList = data.DATA;
                        var count = data.COUNT;
                        var pageCount = Math.ceil(count / pageSize);
                        if(null != newsList && ‘‘ != newsList) {
                            var html = "";
                            for(i = 0; i < newsList.length; i++) {
                                html += ‘<div class="advisoryCenter_News_mould">‘;
                                html += ‘<div class="advisoryCenter_News_picture">‘;
                                html += ‘<img src="‘ + newsList[i].imgUrl + ‘"/>‘;
                                html += ‘</div>‘;
                                html += ‘<div class="advisoryCenter_News_text">‘;
                                html += ‘<div class="advisoryCenter_News_title">‘;
                                html += ‘<a href="news.html?id=‘ + newsList[i].id + ‘">‘ + newsList[i].newsTitle + ‘</a>‘;
                                html += ‘</div>‘;
                                html += ‘<div class="advisoryCenter_News_information">‘;
                                html += ‘<span>‘ + newsList[i].newsOriginate + ‘</span>‘;
                                html += ‘<span></span>‘;
                                html += ‘<span>‘ + newsList[i].newsType + ‘</span>‘;
                                html += ‘<span>‘ + newsList[i].startTime + ‘</span>‘;
                                html += ‘<span></span>‘;
                                html += ‘</div>‘;
                                html += ‘<div class="advisoryCenter_News_article">‘ + newsList[i].newsDesc + ‘</div>‘;
                                html += ‘</div>‘;
                                html += ‘</div>‘;
                            }
                            html += ‘<div class="m-style M-box"></div>‘;
                            $(‘#newsList‘).html(html);
                            //分页
                            $(".M-box").pagination({
                                pageCount: pageCount,
                                coping: true,
                                current: pageIndex,
                                homePage: ‘首页‘,
                                endPage: ‘末页‘,
                                prevContent: ‘上页‘,
                                nextContent: ‘下页‘,
                                callback: function(api) {
                                    pageCallback(api);
                                }
                            });
                        } else {
                            document.getElementById(‘newsList‘).innerHTML = "暂无数据"
                        }
                    } else {
                        layer.msg("", {
                            time: 1500,
                            content: data.MSG
                        });
                    }
                } else {
                    layer.msg("", {
                        time: 1500,
                        content: ‘服务异常‘
                    });
                }
            },
            error: function() {
                layer.msg("", {
                    time: 1500,
                    content: ‘查询新闻失败‘
                });
            }
        });

  翻页方法

//翻页调用   
    function pageCallback(api) {
        var pageIndex = api.getCurrent() //获取当前代码
        queryNewsList(pageIndex);
    }

 

以上是关于JQuery的分页插件pagination.js的主要内容,如果未能解决你的问题,请参考以下文章

采用Vue2.0开发的分页js组件

jQuery 分页插件(jQuery.pagination.js)ajax 实现分页

jquery.pagination.js分页插件的使用

jquery.pagination.js 分页插件,一直执行回调方法,死循环了

jquery.pagination.js分页使用教程

pagination分页插件使用