(function($){
    $.fn.extend({ //给jQuery对象添加方法
        MyPagination: function(options) {
            var defaults = {
                height:400,
                fadeSpeed:0
            };
            var options = $.extend(defaults, options);            //Creating a reference to the object
            var objContent = $(this);            // other inner variables
            var fullPages = new Array();
            var subPages = new Array();
            var height = 0;
            var lastPage = 1;
            var paginatePages;            // initialization function
            init = function() {
                objContent.children().each(function(i){
                    if (height + this.clientHeight > options.height) {
                        fullPages.push(subPages);
                        subPages = new Array();
                        height = 0;
                    }                    height += this.clientHeight;
                    subPages.push(this);
                });                if (height > 0) {
                    fullPages.push(subPages);
                }                // wrapping each full page
                $(fullPages).wrap("<div class='page'></div>");                // hiding all wrapped pages
                objContent.children().hide();                // making collection of pages for pagination
                paginatePages = objContent.children();                // show first page
                showPage(lastPage);                // draw controls
                showPagination($(paginatePages).length);
            };            // update counter function
            updateCounter = function(i) {
                $('#content #page_number').html(i);
            };            // show page function
            showPage = function(page) {
                i = page - 1; 
                if (paginatePages[i]) {                    // hiding old page, display new one
                    $(paginatePages[lastPage]).fadeOut(options.fadeSpeed);
                    lastPage = i;
                    $(paginatePages[lastPage]).fadeIn(options.fadeSpeed);                    // and updating counter
                    updateCounter(page);
                }
            };
            // show pagination function (draw switching numbers)
            showPagination = function(numPages) {
                var pagins = '';
                for (var i = 1; i <= numPages; i++) {
                    pagins += '<li><a href="#" onclick="showPage(' + i + '); return false;">' + i + '</a></li>';
                }
                $('.pagination li:first-child').after(pagins);
            };            // perform initialization
            init();            // and binding 2 events - on clicking to Prev
            $('#prev').click(function() {
                showPage(lastPage);
            });
            // and Next
            $('#next').click(function() {
                showPage(lastPage+2);
            });        }
    });
})(jQuery);// custom initialization
jQuery(window).load(function() {
    $("#content").MyPagination({height: 400, fadeSpeed:0});
});
有人懂这段代码,我想问一下如何在这个基础上添加搜索功能,和页面跳转功能jQuery搜索

解决方案 »

  1.   

    $('#next').click(function() {
                    showPage(lastPage+2);
                });
    照着这个改改
      

  2.   

      MyPagination: function(options) {}这个里面吧,追加参数或者用一个json对象封装
      

  3.   

    你看过这段代码的效果吗?(猜测可能性比较小) objContent这个对象貌似是存数据的,可以考虑从它入手
      

  4.   

    看过了,这个是miniui,这个是挺不错的。但是这个好像有试用期,是收费的。
      

  5.   

    http://www.miniui.com/download/v2/   点开下免费的v2版