1 (function ($) {
2 var PageFunc = function PageFunc() { }
3 $.PageFunc = function (Total, PageSize, curPageNum, FunUrl) {
4 if (PageSize == "" || PageSize == null || PageSize == undefined) {
5 PageSize = 10;
6 }
7 if (curPageNum == "" || curPageNum == null || curPageNum == undefined) {
8 curPageNum = 1;
9 }
10 //计算总页数
11 Total = parseInt(Total); //总记录数
12 PageSize = parseInt(PageSize); //每页显示数
13 curPageNum = parseInt(curPageNum); //当前页
14 //总页数
15 var AllPage = Math.floor(Total / PageSize);
16 if (Total % PageSize != 0) {
17 AllPage++;
18 }
19
20 var navHtml = "";
21
22 if (curPageNum <= 0)
23 curPageNum = 1;
24 if (AllPage > 1) {
25 if (curPageNum != 1) {
26 //处理首页连接
27 navHtml += "<span><a href=\"javascript:" + FunUrl + "('1')\" >|<</a></span> ";
28 }
29 if (curPageNum > 1) {
30 //处理上一页的连接
31 navHtml += "<span><a href=\"javascript:" + FunUrl + "('" + (curPageNum - 1) + "')\" ><<</a></span> ";
32 }
33 else {
34 navHtml += "<span class=\"disabled\"><<</span> ";
35 }
36
37 var currint = 5;
38 for (var i = 0; i <= 10; i++) {
39 //一共最多显示10个页码,前面5个,后面5个
40 if ((curPageNum + i - currint) >= 1 && (curPageNum + i - currint) <= AllPage)
41 if (currint == i) {
42 //当前页处理
43 navHtml += "<span lass=\"current\">[" + curPageNum + "]</span> ";
44 }
45 else {
46 //一般页处理
47 var n = curPageNum + i - currint;
48 navHtml += "<a href=\"javascript:" + FunUrl + "('" + (parseInt(n)) + "')\">" + n + "</a> ";
49 }
50 }
51 if (curPageNum < AllPage) {
52 //处理下一页的链接
53 navHtml += "<span><a href=\"javascript:" + FunUrl + "('" + (parseInt(curPageNum) + 1) + "')\">>></a></span> ";
54 }
55 else {
56 navHtml += "<span class=\"disabled\">>></span> ";
57 }
58
59 if (curPageNum != AllPage) {
60 navHtml += "<span><a href=\"javascript:" + FunUrl + "('" + AllPage + "')\" >>|</a></span>  ";
61 }
62
63 }
64
65 navHtml += "<span>[" + curPageNum + "/" + AllPage + "]</span> ";
66
67 return navHtml;
68
69 };
70
71 })(jQuery);
下边是调用方法:
1 function QueryList(curpage) {
2 if (curpage == "" || curpage == null || curpage == undefined) {
3 curpage = 1;
4 }
5 var pagesize = 10;
6
7 var Countys = $("#Countys").val(); //县
8 var enddate = $("#enddate").val(); //结束时间
9 var begindate = $("#begindate").val(); //开始时间
10 $.ajax({
11 url: "",
12 type: "POST",
13 data: { "Countys": Countys, "enddate": enddate, "begindate": begindate, "curpage": curpage, "pagesize": pagesize },
14 dataType: "json",
15 error: function (xhr, status, errMsg) { window.location.href = "/CommonError/index/" + errMsg.code + "?txt=" + errMsg.msg; },
16 success: function (mydata) {
17 var str = "";
18 $.each(mydata.Tdata, function (i, item) {
19
20 str += "<tr>"
21 str += "<td>" + $.FormatDateTime(item.ControlBeginTime, false) + "</td>";
22 str += "<td>" + $.FormatDateTime(item.ControlEndTime, false) + "</td>";
23 str += "<td>" + item.Name + "</td>";
24 str += "<td>" + item.PlateNumber + "</td>";
25 str += "<td>" + item.ControlDept + "</td>";
26 if (item.IsAll == "0") {
27 str += "<td>全县布控</td>";
28 }
29 else {
30 str += "<td>按卡口点布控</td>";
31 }
32 str += "<td>" + item.IsAll == "0" ? "全县布控" : "按卡口点布控" + "</td>";
33 str += "<td>修改</td>";
34 str += "<td>删除</td>";
35 str += "<td>详细</td>";
36 str + "</tr>";
37 });
38
39 $("#srh_rslt tbody").html(str);
40
41 $(".pagination").html($.PageFunc(mydata.total, pagesize, curpage, "QueryList"));
42 }
43 });
44 }
<style> .pageline { font-size:12px; font-family:"宋体"; width:100%; text-align:center; margin-bottom:5px; } .disabled { display:none; } .current { color:red; } </style>