//分页插件1
function showView(option) {
    //参数定义id,页容量,当前页,总数,页总数
    var id = option.id,
         pageSize = option.pageSize,
         currentPage = option.currentPage,
         totalCount = option.totalCount,
         pageCount = 0;
    var textHtml = "";
    if (Number(pageSize) && Number(totalCount) && Number(currentPage)) {
        pageCount = (parseInt(totalCount / pageSize)) + 1;
        textHtml = "<span class='coseSpan' value='1'><a href='javascript:;'>首页</a></span>";
        if (currentPage > 1) {
            textHtml += "<span class='coseSpan' value = '" + (parseInt(currentPage) - 1) + "'><a href='javascript:;'>上一页</a></span>";
        } else {
            textHtml += "<span class='eleSpan' value = '1'>上一页</span>";
        }
        if (currentPage < pageCount) {
            textHtml += "<span class='coseSpan' value = '" + (parseInt(currentPage) + 1) + "'><a href='javascript:;'>下一页</a></span>";
        } else {
            textHtml += "<span class='eleSpan' value = '" + (parseInt(currentPage) + 1) + "'>下一页</span>";
        }
        textHtml += "<span class = 'coseSpan' value='" + parseInt(pageCount) + "'><a href='javascript:;'>尾页</a></span>";
    } else {
        textHtml += "<span>首页</span><span>上一页</span><span>下一页</span><span>尾页</span>";
    }
    //加载页面
    $("#" + id).html(textHtml);
    //注册事件
    $("span .coseSpan").unbind("click").click(function() {
        //获取当前页
        var pageIndex = $(this).attr("value");
        if (pageIndex && Number(pageIndex)) {
            option.getPrassBar(parseInt(pageIndex), pageSize);
        }
    });
}

//分页插件2
function showPageBar(option) {
    var id = option.id,
        pageSize = option.pageSize,
        currentPage = option.currentPage,
        toltalCount = option.toltalCount;
    var textHtml = "";
    if (Number(toltalCount) && Number(pageSize) && Number(currentPage)) {
        //获取有多少页
        pageCount = parseInt(toltalCount / pageSize) + 1;
        //计算开始下标
        var startIndex = (currentPage - 1) * pageSize + 1,
        endIndex = currentPage * pageSize;
        if (endIndex < toltalCount) {
            textHtml += "显示" + startIndex + "到" + endIndex + "条记录,共" + toltalCount + "条记录&nbsp";
        } else {
            textHtml += "显示" + startIndex + "到" + toltalCount + "条记录,共" + toltalCount + "条记录&nbsp";
        }
        if (currentPage == 1) {
            textHtml += "<span class='NowcChangePage' value='1' title='首页'><<</span>&nbsp<span class='NowChangePage' value='1' title='上一页'><</span>&nbsp";
        } else {
            textHtml += "<span class='changePage' value='1' title='首页'><a href='javascrpit:void(0)'><<</a></span>&nbsp<span class='changePage' value='" + (currentPage - 1) + "' title='上一页'><a href='javascrpit:void(0)'><</a></span>&nbsp";
        }
        if (pageCount > 6) {
            if ((currentPage == 1 || currentPage == 2)) {
                for (var i = 1; i <= 3; i++) {
                    if (i == currentPage) {
                        textHtml += "<span class='changePage' value='" + i + "'>" + i + "</span>";
                    } else {
                        textHtml += "<span class='changePage' value='" + i + "'><a href='javascript:void(0)'>" + i + "</a></span>";
                    }
                }
                textHtml += "...";
                for (var n = (pageCount - 2); n <= pageCount; n++) {
                    textHtml += "<span class='changePage' value='" + n + "'><a href='javascript:void(0)'>" + n + "</a></span>";
                }
            } else {
                if ((pageCount - currentPage) > 4) {
                    for (var i = (currentPage - 1); i <= (currentPage + 1); i++) {
                        if (i == currentPage) {
                            textHtml += "<span class='changePage' value='" + i + "'>" + i + "</span>";
                        } else {
                            textHtml += "<span class='changePage' value='" + i + "'><a href='javascript:void(0)'>" + i + "</a></span>";
                        }
                    }
                    textHtml += "...";
                    for (var n = (pageCount - 2); n <= pageCount; n++) {
                        textHtml += "<span class='changePage' value='" + n + "'><a href='javascript:void(0)'>" + n + "</a></span>";
                    }
                } else {
                    //找出起始元素
                    for (var n = (pageCount - 5); n <= pageCount; n++) {
                        if (n == currentPage) {
                            textHtml += "<span class='changePage' value='" + n + "'>" + n + "</span>";
                        } else {
                            textHtml += "<span class='changePage' value='" + n + "'><a href='javascript:void(0)'>" + n + "</a></span>";
                        }
                    }
                }
            }
        } else {
            for (var i = 1; i <= parseInt(pageCount); i++) {
                if (currentPage == i) {
                    textHtml += "<span class='NowchangePage' value='" + i + "'>" + i + "</span>";
                } else {
                    textHtml += "<span class='changePage' value='" + i + "'><a href='javascrpit:void(0)'>" + i + "</a></span>";
                }
            }
        }
        if (currentPage == pageCount) {
            textHtml += "&nbsp<span class='NowcChangePage' value='1' title='下一页'>></span>&nbsp<span class='NowChangePage' value='1' title='尾页'>>></span>";
        } else {
            textHtml += "&nbsp<span class='changePage' value='" + (currentPage + 1) + "' title='下一页'><a href='javascrpit:void(0)'>></a></span>&nbsp<span class='changePage' value='" + pageCount + "' title='尾页'><a href='javascrpit:void(0)'>>></a></span>";
        }

$("#" + id).html(textHtml);
        $("span .changePage").unbind("click").click(function() {
            var currentIndex = parseInt($(this).attr("value"));
            if (Number(currentIndex)) {
                option.getPrassBar(parseInt(currentIndex), pageSize);
            }
        });
    }

}

//html代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="分页插件._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>

<script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>

<script src="js/paging.js" type="text/javascript"></script>

<script type="text/javascript">
        function loadPage(currentPage,pageSize) {
            showView({
            id: "page",
                pageSize: pageSize,
                currentPage: currentPage,
                totalCount: 0,
                getPrassBar: function(pageIndex, pageSize) {
                alert("页下标:" + pageIndex + "页容量:" + pageSize);
                    loadPage(pageIndex, pageSize);
                }
            });
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="button" value="加载分页控件" onclick="loadPage(1,10)" /></div>
    <div>
        <span id="page"></span>
    </div>
    </form>
</body>
</html>

js分页插件的更多相关文章

  1. Bootstrap的js分页插件属性介绍

    Bootstrap Paginator是一款基于Bootstrap的js分页插件,功能很丰富,个人觉得这款插件已经无可挑剔了.它提供了一系列的参数用来支持用户的定 制,提供了公共的方法可随时获得插件状 ...

  2. 一款基于Bootstrap的js分页插件bootstrap-paginator使用实例

    Bootstrap Paginator是一款基于Bootstrap的js分页插件,功能很丰富.它提供了一系列的参数用来支持用户的定制,提供了公共的方法可随时获得插件状态的改变,以及事件来监听用户的动作 ...

  3. Jquery.Page.js 分页插件的使用

    1.简单直接贴代码 需要引用以下样式和脚本 <link href="~/Scripts/Page/pager.css" rel="stylesheet" ...

  4. JQuery.Page.js分页插件的使用

    1.简单直接贴代码 需要引用以下样式和脚本 <link href="~/Scripts/Page/pager.css" rel="stylesheet" ...

  5. twbsPagination.js分页插件

    分页插件在使用时注意,如果页面中存在其他异步加载的数据,在运行分页方法第一次后,页面上的分页样式与分页中的data数据就是第一次的数据,如果异步加载重新在页面上录入数据,并希望分页继续在新的数据上实现 ...

  6. Js分页插件,支持页面跳转

    这里先给出API: 你只需要提供一个对象涉及以下几项属性,你来设置属性值,通过jq对象链式调用page()以参数形式来加载这个对象,按照参数要求会自动生成分页功能, 参数中pageEvent是可以让你 ...

  7. js 分页插件(jQuery)

    参考:http://www.jb51.net/article/117191.htm 侵删 css 部分 @charset "utf=8"; *{ box-sizing: borde ...

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

    Pagination的相关参数: Pagination使用的核心代码:         //回调函数         function pageselectCallback(page_index, j ...

  9. 一个比较轻巧好用的js分页插件,可ajax可url

    var pageNav = pageNav || {}; pageNav.fn = null; pageNav.pre = "pre"; pageNav.next = " ...

随机推荐

  1. android获取年月日时分秒

    Calendar calendar=Calendar.getInstance(); //获取当前时间,作为图标的名字 String year=calendar.get(Calendar.YEAR)+& ...

  2. Eddy's mistakes

    Problem Description Eddy usually writes  articles ,but he likes mixing the English letter uses, for ...

  3. [CH#56]过河(贪心)

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2356%20-%20%E5%9B%BD%E5%BA%86%E8%8A%82%E6%AC%A2%E4%B9%90% ...

  4. MySQL基于域名做高可用切换(Consul初试)

    一,Consul功能介绍 服务发现 - Consul的客户端可用提供一个服务,比如 api 或者mysql ,另外一些客户端可用使用Consul去发现一个指定服务的提供者.通过DNS或者HTTP应用程 ...

  5. 5、Java并发性和多线程-相同线程

    以下内容转自http://tutorials.jenkov.com/java-concurrency/same-threading.html(使用谷歌翻译): 相同线程(同一线程)是一种并发模型,其中 ...

  6. some notes about ADDM and AWR

    Use the sophisticated management and monitoring features of the Oracle DatabaseDiagnostic and Tuning ...

  7. 阿里云nginx创建多站点

    最近开始用阿里云的vps,用了它的一键安装包安装了php环境,nginx的.下面记录创建多站点的心得. 首先php安装好后会自带安装一个phpwind的站点. 文件目录存放在 /alidata/www ...

  8. Linux中W与Who命令的使用

    踢掉一个从某个终端连上的用户pkill -kill  -t pts/0 ---------------------------------------------------------------- ...

  9. 大话USB驱动之总线驱动程序

    转载注明出处:http://blog.csdn.net/ruoyunliufeng/article/details/25040009 总线驱动是不用改的.内核都帮我们做好了.为了了解整个USB驱动的体 ...

  10. easyui 后台框架搭建

    近期公司要搭建一个后台管理项目.因为美工缺少 选择使用easyui jquery 框架 仅仅要懂点html js 这个用起来不是难事,看过API.在网上看了些 将它们组装起来 进行改动.因为本人也是第 ...