基於jquery封裝的一個js分頁

來源:互聯網
上載者:User

複製代碼 代碼如下:(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> &nbsp";
}

}

navHtml += "<span>[" + curPageNum + "/" + AllPage + "]</span> ";

return navHtml;

};

})(jQuery);

下邊是調用方法: 複製代碼 代碼如下:function QueryList(curpage) {
if (curpage == "" || curpage == null || curpage == undefined) {
curpage = 1;
}
var pagesize = 10;

var Countys = $("#Countys").val(); //縣
var enddate = $("#enddate").val(); //結束時間
var begindate = $("#begindate").val(); //開始時間
$.ajax({
url: "",
type: "POST",
data: { "Countys": Countys, "enddate": enddate, "begindate": begindate, "curpage": curpage, "pagesize": pagesize },
dataType: "json",
error: function (xhr, status, errMsg) { window.location.href = "/CommonError/index/" + errMsg.code + "?txt=" + errMsg.msg; },
success: function (mydata) {
var str = "";
$.each(mydata.Tdata, function (i, item) {

str += "<tr>"
str += "<td>" + $.FormatDateTime(item.ControlBeginTime, false) + "</td>";
str += "<td>" + $.FormatDateTime(item.ControlEndTime, false) + "</td>";
str += "<td>" + item.Name + "</td>";
str += "<td>" + item.PlateNumber + "</td>";
str += "<td>" + item.ControlDept + "</td>";
if (item.IsAll == "0") {
str += "<td>全縣布控</td>";
}
else {
str += "<td>按卡口點布控</td>";
}
str += "<td>" + item.IsAll == "0" ? "全縣布控" : "按卡口點布控" + "</td>";
str += "<td>修改</td>";
str += "<td>刪除</td>";
str += "<td>詳細</td>";
str + "</tr>";
});

$("#srh_rslt tbody").html(str);

$(".pagination").html($.PageFunc(mydata.total, pagesize, curpage, "QueryList"));
}
});
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.