日期:2014-05-16  浏览次数:20700 次

关于JQuery.pager分页的问题,请各个大侠帮忙看看!
问题:
把数据(json格式)总记录读出来后,给jquery.pager的pagecount参数成功,但是有多少条数据就有多少个页面,没有分页列表,如果有64条数据,就会有64页,要如何才能按每页9条数据进行分页呢。总页数和总记录是什么配置的,谢谢!

JQ代码
JScript code

<script type="text/javascript">
        var count = "";
        //统计总记录
        function RecordCount() {
            $.ajax({
                dataType: "json",
                url: "WebService.asmx/XmltoJson",
                contentType: "application/json;",
                type: "POST",
                success: function (xml) {
                    var json = eval('(' + xml.d + ')');
                    $("#txtCount").val($(json.jinshu.item).length);
                }
            });
        }
        //输出数据
        function InitData(pageclickednumber) {
            $.ajax({
                dataType: 'json',
                url: "WebService.asmx/XmltoJson",
                contentType: "application/json;",
                //data: { pageindex: pageclickednumber },
                type: "POST",
                success: function (xml) {
                    var tbody = "";
                    var json = eval('(' + xml.d + ')');
                    $("#txtCount").val($(json.jinshu.item).length);
                    $.each(json.jinshu.item, function (i, n) {
                        var str = "";
                        str += "<tr><td>" + n["@newsid"] + "</td><td>" + n["@newstitle"] + "</td><td>" + n["@url"] + "</td><td>" + n["@auditortime"] + "</td><td>" + n["@newssort"] + "</td></tr>";
                        tbody += str;
                    });
                    $("#TBODY").append(tbody);
                }
            });            
        }
        //初始化
        $(document).ready(function () {
            RecordCount();
            $("#pager").pager({ pagenumber: 1, pagecount: $("#txtCount").val(), buttonClickCallback: PageClick });
            PageClick(1);
        });
        //回调分页
        PageClick = function (pageclickednumber) {
            $("#pager").pager({ pagenumber: pageclickednumber, pagecount: $("#txtCount").val(), buttonClickCallback: PageClick });
            InitData(pageclickednumber);
        }
    </script>



jquery.pager.js
JScript code

(function($) {

    $.fn.pager = function(options) {

        var opts = $.extend({}, $.fn.pager.defaults, options);

        return this.each(function() {

        // empty out the destination element and then render out the pager with the supplied options
            $(this).empty().append(renderpager(parseInt(options.pagenumber), parseInt(options.pagecount), options.buttonClickCallback));
            
            // specify correct cursor activity
            $('.pages li').mouseover(function() { document.body.style.cursor = "pointer"; }).mouseout(function() { document.body.style.cursor = "auto"; });
        });
    };

    // render and return the pager with the supplied options
    function renderpager(pagenumber, pagecount, buttonClickCallback) {

        // setup $pager to hold render
        var $pager = $('<ul class="pages"></ul>');

        // add in the previous and next buttons
        $pager.append(renderButton('first', pagenumber, pagecount, buttonClickCallback)).append(renderButton('prev', pagenumber, pagecount, buttonClickCallback));

        // pager currently only ha