zoukankan      html  css  js  c++  java
  • 基于jquery封装的一个js分页

    (function ($) { 
    var PageFunc = function PageFunc() { } 
    $.PageFunc = function (Total, PageSize, curPageNum, FunUrl) { 
    if (PageSize == "" || PageSize == null || PageSize == undefined) { 
    PageSize = 10; 
    } 
    if (curPageNum == "" || curPageNum == null || curPageNum == undefined) { 
    curPageNum = 1; 
    } 
    //计算总页数 
    Total = parseInt(Total); //总记录数 
    PageSize = parseInt(PageSize); //每页显示数 
    curPageNum = parseInt(curPageNum); //当前页 
    //总页数 
    var AllPage = Math.floor(Total / PageSize); 
    if (Total % PageSize != 0) { 
    AllPage++; 
    } 
    
    var navHtml = ""; 
    
    if (curPageNum <= 0) 
    curPageNum = 1; 
    if (AllPage > 1) { 
    if (curPageNum != 1) { 
    //处理首页连接 
    navHtml += "<span><a href=\"javascript:" + FunUrl + "('1')\" >|<</a></span> "; 
    } 
    if (curPageNum > 1) { 
    //处理上一页的连接 
    navHtml += "<span><a href=\"javascript:" + FunUrl + "('" + (curPageNum - 1) + "')\" ><<</a></span> "; 
    } 
    else { 
    navHtml += "<span class=\"disabled\"><<</span> "; 
    } 
    
    var currint = 5; 
    for (var i = 0; i <= 10; i++) { 
    //一共最多显示10个页码,前面5个,后面5个 
    if ((curPageNum + i - currint) >= 1 && (curPageNum + i - currint) <= AllPage) 
    if (currint == i) { 
    //当前页处理 
    navHtml += "<span lass=\"current\">[" + curPageNum + "]</span> "; 
    } 
    else { 
    //一般页处理 
    var n = curPageNum + i - currint; 
    navHtml += "<a href=\"javascript:" + FunUrl + "('" + (parseInt(n)) + "')\">" + n + "</a> "; 
    } 
    } 
    if (curPageNum < AllPage) { 
    //处理下一页的链接 
    navHtml += "<span><a href=\"javascript:" + FunUrl + "('" + (parseInt(curPageNum) + 1) + "')\">>></a></span> "; 
    } 
    else { 
    navHtml += "<span class=\"disabled\">>></span> "; 
    } 
    
    if (curPageNum != AllPage) { 
    navHtml += "<span><a href=\"javascript:" + FunUrl + "('" + AllPage + "')\" >>|</a></span>  "; 
    } 
    
    } 
    
    navHtml += "<span>[" + curPageNum + "/" + AllPage + "]</span> "; 
    
    return navHtml; 
    
    }; 
    
    })(jQuery); 
    

      调用:

    (function ($) { 
    var PageFunc = function PageFunc() { } 
    $.PageFunc = function (Total, PageSize, curPageNum, FunUrl) { 
    if (PageSize == "" || PageSize == null || PageSize == undefined) { 
    PageSize = 10; 
    } 
    if (curPageNum == "" || curPageNum == null || curPageNum == undefined) { 
    curPageNum = 1; 
    } 
    //计算总页数 
    Total = parseInt(Total); //总记录数 
    PageSize = parseInt(PageSize); //每页显示数 
    curPageNum = parseInt(curPageNum); //当前页 
    //总页数 
    var AllPage = Math.floor(Total / PageSize); 
    if (Total % PageSize != 0) { 
    AllPage++; 
    } 
    
    var navHtml = ""; 
    
    if (curPageNum <= 0) 
    curPageNum = 1; 
    if (AllPage > 1) { 
    if (curPageNum != 1) { 
    //处理首页连接 
    navHtml += "<span><a href=\"javascript:" + FunUrl + "('1')\" >|<</a></span> "; 
    } 
    if (curPageNum > 1) { 
    //处理上一页的连接 
    navHtml += "<span><a href=\"javascript:" + FunUrl + "('" + (curPageNum - 1) + "')\" ><<</a></span> "; 
    } 
    else { 
    navHtml += "<span class=\"disabled\"><<</span> "; 
    } 
    
    var currint = 5; 
    for (var i = 0; i <= 10; i++) { 
    //一共最多显示10个页码,前面5个,后面5个 
    if ((curPageNum + i - currint) >= 1 && (curPageNum + i - currint) <= AllPage) 
    if (currint == i) { 
    //当前页处理 
    navHtml += "<span lass=\"current\">[" + curPageNum + "]</span> "; 
    } 
    else { 
    //一般页处理 
    var n = curPageNum + i - currint; 
    navHtml += "<a href=\"javascript:" + FunUrl + "('" + (parseInt(n)) + "')\">" + n + "</a> "; 
    } 
    } 
    if (curPageNum < AllPage) { 
    //处理下一页的链接 
    navHtml += "<span><a href=\"javascript:" + FunUrl + "('" + (parseInt(curPageNum) + 1) + "')\">>></a></span> "; 
    } 
    else { 
    navHtml += "<span class=\"disabled\">>></span> "; 
    } 
    
    if (curPageNum != AllPage) { 
    navHtml += "<span><a href=\"javascript:" + FunUrl + "('" + AllPage + "')\" >>|</a></span>  "; 
    } 
    
    } 
    
    navHtml += "<span>[" + curPageNum + "/" + AllPage + "]</span> "; 
    
    return navHtml; 
    
    }; 
    
    })(jQuery); 
    

      

    ===============转自============

    http://www.jb51.net/article/28909.htm

  • 相关阅读:
    15 | 二分查找(上):如何用最省内存的方式实现快速查找功能?
    11 | 线程:如何让复杂的项目并行执行?
    数据结构与算法-10-递归调用
    (图文并茂,权威最详细)Wireshark抓包分析 TCP三次握手/四次挥手详解
    总结-自己傻的坑学习java spingboot不仔细
    网络抓包
    数据库简介
    JavaSE基础之Map与Collection
    JavaSE基础之抽象类与接口
    JavaSE基础之重载和重写
  • 原文地址:https://www.cnblogs.com/zjw520/p/3015407.html
Copyright © 2011-2022 走看看