js分页

js:

var pageCount = 5; //每页显示最多页数
        var pageNum = 0; //总页数
        var currentPage = 1; //当前页
        var startcount = 0;
        var endcount = 0;
        jQuery(function () {
            jQuery.post("fordata.ashx", { "type": 0, "Action": "GetPageCount", "huodongid": huodongid }, function (data) {
                pageNum = data;
                GetPageData(currentPage);
            });
        });
        //加载页数
        function DisplayPage() {
            var html = '';
            html += "<a href='javascript:;' id='homePage'>首页</a><a href='javascript:;' id='prePage'>上一页</a>";
            if (currentPage == 1 && pageNum >= pageCount) {
                startcount = 1;
                endcount = 5;
            } else if (currentPage != 1 && pageNum >= pageCount) {
                if (currentPage == startcount) {
                    if (currentPage - 2 <= 0) {
                        startcount = 1;
                    }
                    else {
                        startcount = currentPage - 2;
                        endcount = Number(currentPage) + 2;
                    }
                    if (endcount <= pageCount) {
                        endcount = pageCount;
                    }
                    if (Number(currentPage) + 2 >= pageNum) {
                        endcount = pageNum;
                    }
                }
                if (currentPage == endcount) {
                    if (currentPage - 2 <= 0) {
                        startcount = 1;
                    }
                    else {
                        startcount = currentPage - 2;
                        endcount = Number(currentPage) + 2;
                    }
                    if (endcount <= pageCount) {
                        endcount = pageCount;
                    }
                    if (Number(currentPage) + 2 >= pageNum) {
                        endcount = pageNum;
                    }
                }
            }
            else {
                startcount = 1;
                endcount = pageNum;
            }
            for (var i = startcount; i <= endcount; i++) {
                html += "<a href='javascript:;' name='page_a'>" + i + "</a>";
            }
            html += "<a href='javascript:;' id='nextPage'>下一页</a><a href='javascript:;' id='lastPage'>末页</a>";
            jQuery('#pagenumLabel').html(html);
            //首页
            jQuery('#homePage').click(function () {
                GetPageData(1);
            });
            //上一页
            jQuery('#prePage').click(function () {
                var pageIndex = currentPage - 1;
                if (pageIndex <= 0) {
                    pageIndex = 1;
                    currentPage = 1;
                }
                GetPageData(pageIndex);
            });
            //下一页
            jQuery('#nextPage').click(function () {
                var pageIndex = currentPage + 1;
                if (pageIndex >= pageNum) {
                    pageIndex = pageNum;
                    currentPage = pageNum;
                }
                GetPageData(pageIndex);
            });
            jQuery('#lastPage').click(function () {
                GetPageData(pageNum);
            });
            //点击页数时加载该页对应数据
            jQuery('a[name="page_a"]').click(function () {
                GetPageData(jQuery(this).text());
            });
        }
        //加载每页内容
        function GetPageData(pageIndex) {
            currentPage = pageIndex;
            DisplayPage();
            jQuery.getJSON("fordata.ashx", { "type": 0, "huodongid": huodongid, "Action": "GetPageData", "PageNum": currentPage, "top": 60, "left": 600 }, function (data) {
                var html = '';
                jQuery(data).each(function (i, model) {
                    html += "<div class='xy' id='bid_" + model.id + "' style='position: absolute;margin-left:" + model.left + "px;margin-top:" + model.top + "px;'><div class='close_a'><a href='javascript:;' name='close' check='" + model.id + "'>x</a></div><h5>" + model.title + "</h5><p>" + model.content + "</p></div>";
                });
                jQuery('#ulCategory').html(html);
                jQuery('a[name="close"]').click(function () {
                    jQuery('#bid_' + jQuery(this).attr('check') + '').hide();
                });
                if (html.length > 0) {
                    jQuery('.xy').draggable();
                    jQuery(".xy").mousedown(function () {
                        jQuery('.xy').css("z-index", "1");
                        jQuery(this).css("z-index", "2");
                    });
                    jQuery(".xy").mouseup(function () {
                        jQuery(this).droppable();
                    });
                }
            });
        }


一般处理程序:

int pageDisCount = 50;//每页多少条数据
        string strAction = context.Request.Params["Action"];
        //取页数 
        if(strAction == "GetPageCount")
        {
            string strSQL = "select COUNT(1) from tbl_vowwall where type=@huodongid";
            SDN.DB.DAO.ParameterBox pb = new SDN.DB.DAO.ParameterBox("@huodongid",huodongid);
            int intRecordCount = Convert.ToInt32(SDN.DB.DAO.SqlHelper.ExecuteScalar(strSQL,pb));//SqlHelper.ExecuteScalar(strSQL);
            int intPageCount = intRecordCount / pageDisCount;
            if(intRecordCount % pageDisCount != 0)
            {
                intPageCount++;
            }
            context.Response.Write(intPageCount);
        }//取每页数据 
        else if(strAction == "GetPageData")
        {
            int top = string.IsNullOrEmpty(context.Request.Params["top"]) ? 260 : Convert.ToInt32(context.Request.Params["top"]);
            int left = string.IsNullOrEmpty(context.Request.Params["left"]) ? 700 : Convert.ToInt32(context.Request.Params["left"]);
            int intPageNum = Convert.ToInt32(context.Request.Params["PageNum"]);
            string sql = "select top " + pageDisCount + " id,title,content,''as [top],'' as [left] from tbl_vowwall where type=@huodongid and id not in (select top (" + pageDisCount + "*(" + intPageNum + "-1)) id from tbl_vowwall where type=@huodongid order by id desc) order by id desc";
            SDN.DB.DAO.ParameterBox pb = new SDN.DB.DAO.ParameterBox("@huodongid",huodongid);
            SDN.Common.VO.DataObjectList datas = SDN.Common.VO.DataLoader.LoaderDataObjectListBySql(sql,pb);
            SDN.Common.VO.DataObjectList list = new SDN.Common.VO.DataObjectList();
            Random r = new Random();
            foreach(SDN.Common.VO.DataObject obj in datas)
            {
                obj["id"] = obj["id"];
                obj["content"] = obj["content"];
                obj["title"] = obj["title"];
                obj["top"] = r.Next(top);
                obj["left"] = r.Next(left);
                list.Add(obj);
            }
            context.Response.Write(list.GetJSON());
            context.Response.End();
        }


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zaobanche

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值