成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導(dǎo)航首頁 ? 技術(shù)教程 ? jquery插件pagination實現(xiàn)無刷新ajax分頁
全站頭部文字 我要出現(xiàn)在這里
jquery插件pagination實現(xiàn)無刷新ajax分頁 632 2024-03-24   

1、前臺使用ajax無刷新分頁,主要需要生成分頁的工具條,這里使用的是jquery.pagination.js

插件參數(shù)可以參考----張龍豪-jquery.pagination.js分頁

下面貼出代碼

  /**
  * This jQuery plugin displays pagination links inside the selected elements.
  *
  * @author Gabriel Birke (birke *at* d-scribe *dot* de)
  * @version .
  * @param {int} maxentries Number of entries to paginate
  * @param {Object} opts Several options (see README for documentation)
  * @return {Object} jQuery Object
  */
 jQuery.fn.pagination = function(maxentries, opts){
   opts = jQuery.extend({
     items_per_page:,
     num_display_entries:,
     current_page:,
     num_edge_entries:,
     link_to:"#",
     prev_text:"Prev",
     next_text:"Next",
     ellipse_text:"...",
     prev_show_always:true,
     next_show_always:true,
     callback:function(){return false;}
   },opts||{});
   
   return this.each(function() {
     /**
      * 計算最大分頁顯示數(shù)目
      */
     function numPages() {
       return Math.ceil(maxentries/opts.items_per_page);
     }  
     /**
      * 極端分頁的起始和結(jié)束點,這取決于current_page 和 num_display_entries.
      * @返回 {數(shù)組(Array)}
      */
     function getInterval() {
       var ne_half = Math.ceil(opts.num_display_entries/);
       var np = numPages();
       var upper_limit = np-opts.num_display_entries;
       var start = current_page>ne_half?Math.max(Math.min(current_page-ne_half, upper_limit), ):;
       var end = current_page>ne_half?Math.min(current_page+ne_half, np):Math.min(opts.num_display_entries, np);
       return [start,end];
     }
     
     /**
      * 分頁鏈接事件處理函數(shù)
      * @參數(shù) {int} page_id 為新頁碼
      */
     function pageSelected(page_id, evt){
       current_page = page_id;
       drawLinks();
       var continuePropagation = opts.callback(page_id, panel);
       if (!continuePropagation) {
         if (evt.stopPropagation) {
           evt.stopPropagation();
         }
         else {
           evt.cancelBubble = true;
         }
       }
       return continuePropagation;
     }
     
     /**
      * 此函數(shù)將分頁鏈接插入到容器元素中
      */
     function drawLinks() {
       panel.empty();
       var interval = getInterval();
       var np = numPages();
       // 這個輔助函數(shù)返回一個處理函數(shù)調(diào)用有著正確page_id的pageSelected。
       var getClickHandler = function(page_id) {
         return function(evt){ return pageSelected(page_id,evt); }
       }
       //輔助函數(shù)用來產(chǎn)生一個單鏈接(如果不是當(dāng)前頁則產(chǎn)生span標(biāo)簽)
       var appendItem = function(page_id, appendopts){
         page_id = page_id<?:(page_id<np?page_id:np-); // 規(guī)范page id值
         appendopts = jQuery.extend({text:page_id+, classes:""}, appendopts||{});
         if(page_id == current_page){
           var lnk = jQuery("<a href class='currentPage'>" + (appendopts.text) + "</a>");
         }else{
           var lnk = jQuery("<a>"+(appendopts.text)+"</a>")
             .bind("click", getClickHandler(page_id))
             .attr('href', opts.link_to.replace(/__id__/,page_id));    
         }
         if (appendopts.classes) { lnk.addClass(appendopts.classes); }
         panel.append(lnk);
       }
       //產(chǎn)生描述
       panel.append("<span>共有 " + maxentries + " 條記錄,當(dāng)前第 <b>" + (current_page + ) + "</b>/" + np + " 頁</span>");
       
       // 產(chǎn)生"Previous"-鏈接
       if(opts.prev_text && (current_page > || opts.prev_show_always)){
         appendItem(current_page-,{text:opts.prev_text, classes:"prev"});
       }
       // 產(chǎn)生起始點
       if (interval[] > && opts.num_edge_entries > )
       {
         var end = Math.min(opts.num_edge_entries, interval[]);
         for(var i=; i<end; i++) {
           appendItem(i);
         }
         if(opts.num_edge_entries < interval[] && opts.ellipse_text)
         {
           jQuery("<a href>"+opts.ellipse_text+"</a>").appendTo(panel);
         }
       }
       // 產(chǎn)生內(nèi)部的些鏈接
       for(var i=interval[]; i<interval[]; i++) {
         appendItem(i);
       }
       // 產(chǎn)生結(jié)束點
       if (interval[] < np && opts.num_edge_entries > )
       {
         if(np-opts.num_edge_entries > interval[]&& opts.ellipse_text)
         {
           jQuery("<a href>"+opts.ellipse_text+"</a>").appendTo(panel);
         }
         var begin = Math.max(np-opts.num_edge_entries, interval[]);
         for(var i=begin; i<np; i++) {
           appendItem(i);
         }
         
       }
       // 產(chǎn)生 "Next"-鏈接
       if(opts.next_text && (current_page < np- || opts.next_show_always)){
         appendItem(current_page+,{text:opts.next_text, classes:"next"});
       }
     }
     
     //從選項中提取current_page
     var current_page = opts.current_page;
     //創(chuàng)建一個顯示條數(shù)和每頁顯示條數(shù)值
     maxentries = (!maxentries || maxentries < )?:maxentries;
     opts.items_per_page = (!opts.items_per_page || opts.items_per_page < )?:opts.items_per_page;
     //存儲DOM元素,以方便從所有的內(nèi)部結(jié)構(gòu)中獲取
     var panel = jQuery(this);
     // 獲得附加功能的元素
     this.selectPage = function(page_id){ pageSelected(page_id);}
     this.prevPage = function(){ 
       if (current_page > ) {
         pageSelected(current_page - );
         return true;
       }
       else {
         return false;
       }
     }
     this.nextPage = function(){ 
       if(current_page < numPages()-) {
         pageSelected(current_page+);
         return true;
       }
       else {
         return false;
       }
     }
     // 所有初始化完成,繪制鏈接
     drawLinks();
     // 回調(diào)函數(shù)
     //opts.callback(current_page, this);
   });
 }

代碼還是比較容易看明白的,可以根據(jù)自己需要修改,這里使用的是自己的樣式

樣式代碼

 .pages {display: inline-block; overflow: hidden;padding: px ;text-align: center; width:%; margin:px ;}
 .pages b{ color:#ef;}
 .pages a { color:#; border: px solid #eee;cursor: pointer;font-size: px;margin-right: px; padding: px px; text-decoration: none; background-color:#fafafa;}
 .pages .currentPage{ background-color: #ae; border: px solid #ae;color: #fff; font-weight: bold;}

原來的css樣式:

 .pagination a {
   text-decoration: none;
   border: px solid #AAE;
   color: #B;
 }
 
 .pagination a, .pagination span {
   display: inline-block;
   padding: .em .em;
   margin-right: px;
   margin-bottom: px;
 }
 
 .pagination .current {
   background: #B;
   color: #fff;
   border: px solid #AAE;
 }
 
 .pagination .current.prev, .pagination .current.next{
   color:#;
   border-color:#;
   background:#fff;
 }

可以根據(jù)自己設(shè)計顯示樣式

2、使用方法

2.1、html顯示

 <div class="second-ul-ctn">
       <ul class="second-ul" id="ulProducts">
       </ul>
       <div class="pages">
         <input type="hidden" id="hideTotalCount" />
         <div id="Pagination" class="pagination">
         </div>
       </div>
     </div>

ulProducts中放的是要顯示的數(shù)據(jù),生成的分頁的工具條是放在Pagination中的

2.2 javascript代碼

$(function () {
      searchMyme(0);
      pageInit();
      $("#btnSearch").on("click", function () {
        searchMyme(0);
        pageInit();
        return false;
      });
    });
    function searchMyme(page, pageination) {
      var month = $("#btnMonth").val();
      var obj = {
        Month: month,
        OpType: "getme",
        page: (page + 1)
        , rows: 10
      };
      var url = "../../Controler/FinaceMo/GetStaffIncome_H.ashx";
      $.get(url, obj, function (data) {
        $("#tbIncome").empty();
        var obj = JSON.parse(data);
        var total = obj.Total;
        $("#hideTotalCount").val(total);
        var arrHtml = [];
        $.each(obj.Rows, function (i, data) {
          arrHtml.push("<tr><td>" + (i + 1) + "</td>");
          arrHtml.push("<td>" + data.Account + "</td>");
          arrHtml.push("<td>" + data.Name + "</td>");
          arrHtml.push("<td>" + data.Month + "</td>");
          arrHtml.push("<td>" + data.IncomeAmount + "</td>");
          arrHtml.push("<td><a  class='a-blue'>查看明細(xì)</a></td></tr>");
        });
        $("#tbIncome").append(arrHtml.join(''));
      });
    };
    function pageInit() {
      var totalCount = $("#hideTotalCount").val();
      $("#Pagination").pagination(parseInt(totalCount), {
        items_per_page: 10,
        //current_page: 1,//當(dāng)前選中的頁面默認(rèn)是0,表示第1頁
        num_edge_entries: 2,//兩側(cè)顯示的首尾分頁的條目數(shù),默認(rèn)為0,好像是尾部顯示的個數(shù)
        num_display_entries: 2,//連續(xù)分頁主體部分顯示的分頁條目數(shù),默認(rèn)是10
        link_to: "javascript:void(0)",//分頁的鏈接
        prev_text: "上一頁",
        next_text: "下一頁",
        prev_show_always: true,
        next_show_always: true,
        callback: searchMyIncome
      });
    }

searchMyme是獲取分頁的數(shù)據(jù),將總數(shù)放到一個隱藏的控件中,總數(shù)分頁控件需要使用,這里ajax調(diào)用需要同步執(zhí)行,不然取不到返回的總數(shù)
pageInit() 就是初始化控件

這樣設(shè)置基本就OK了~



主站蜘蛛池模板: 568b水晶头接法图| 电影网1905免费版| 加濑亮| 日韩欧美电影网| 同志电影副歌1080p| 埃尔加,她狼| 《沉默的证人》电影| 97理伦| 夜色斗僵尸| 张达| 女生宿舍1电影| 宋宇宁| 长安长安朗诵报名入口| 黑势力| 康熙王朝50集免费观看投屏电视剧| 一吻定情1| 忏悔三昧念3遍| 9号房间| 砌体工程质量验收规范gb50203---2011 | 朱莉娅·安经典在线观看| 维拉·法梅加| 变形记开头结尾优美段落| 安德鲁·林肯| 欧美黑人天堂av在线| 少年包青天4第四部| 黄视频免费在线看| 抖音手机网页版| 邓为个人介绍| 巴霍巴利王2国语版免费中文版 | 德鲁| 紫依| 豪斯医生第六季| 试看60秒做受小视频| 红电视剧演员表| 饥渴女人的外遇| 吉他谱子| 10000个卫视频道| 最佳女婿 电影| 十大黄色软件推荐免费| cf脚本| 杨剑锋个人资料简介|

!!!站長長期在線接!!!

網(wǎng)站、小程序:定制開發(fā)/二次開發(fā)/仿制開發(fā)等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103