يتصل:
انسخ رمز الكود كما يلي:
فار pageChange = الوظيفة (الفهرس) {
var html = pager("divid", Index, 5, 1000, pageChange, { showGoTo: false, showFirst: false });
}
ينجز:
انسخ رمز الكود كما يلي:
بيجر = وظيفة (divPager، pageIndex، pageSize، TotalCount، pageChange، opt) {
فار theOpt = {
barSize: 5, // عدد الصفحات المعروضة في شريط الترحيل
barTemplate: "{bar} إجماليات {totalPage} صفحات {totalCount} عناصر {goto}"، // عرض القالب
إخفاء تلقائي: صحيح، // ما إذا كان سيتم إخفاءه تلقائيًا
showFirst: true, // ما إذا كان سيتم عرض رابط الصفحة الأولى تلقائيًا عندما يكون TotalPage>barSize
showLast: true, // ما إذا كان سيتم عرض رابط الصفحة الأخيرة تلقائيًا عندما يكون TotalPage>barSize
showGoTo: صحيح، // ما إذا كان سيتم عرض GoTo
autoHideGoTo: true // إذا كان هناك عدد قليل جدًا، ما إذا كان سيتم إخفاء GoTo تلقائيًا
};
إذا (اختيار) {
إذا (opt.barSize)
theOpt.barSize = opt.barSize;
إذا (opt.barTemplate)
theOpt.barTemplate = opt.barTemplate;
إذا (opt.autoHide == خطأ)
theOpt.autoHide = false;
إذا (opt.showFirst == خطأ)
theOpt.showFirst = false;
إذا (opt.showLast = خطأ)
theOpt.showLast = false;
إذا (opt.showGoTo == خطأ)
theOpt.showGoTo = false;
إذا (opt.autoHideGoTo == خطأ)
theOpt.autoHideGoTo = false;
}
var Handles = window.myPagerChanges = (function (x) { return x; } (window.myPagerChanges || {}));
if (!myPagerChanges[divPager]) myPagerChanges[divPager] = pageChange;
var startPage = 0; // الصفحة الرئيسية لشريط الترحيل
var endPage = 0; // نهاية شريط الصفحة
var showFirst = true;
var showLast = true;
إذا (isNaN(pageIndex)) {
pageIndex = 1;
}
pageIndex = parseInt(pageIndex);
إذا (pageIndex <= 0)
pageIndex = 1;
إذا (pageIndex * pageSize > TotalCount) {
pageIndex = Math.ceil(totalCount /pageSize);
}
if (totalCount == 0) { // إذا لم تكن هناك بيانات
document.getElementById(divPager).innerHTML = "";
يعود ""؛
}
var TotalPage = Math.ceil(totalCount /pageSize);
if (theOpt.autoHide && TotalCount <= pageSize) { // إخفاء تلقائي
document.getElementById(divPager).innerHTML = "";
يعود ""؛
}
إذا (totalPage <= theOpt.barSize) {
صفحة البداية = 1؛
endPage = this.totalPage;
theOpt.showLast = theOpt.showFirst = false;
}
آخر {
if (pageIndex <= Math.ceil(theOpt.barSize / 2)) {// الصفحات القليلة الأولى
صفحة البداية = 1؛
endPage = theOpt.barSize;
theOpt.showFirst = false;
}
else if (pageIndex > (totalPage - theOpt.barSize / 2)) {// الصفحات القليلة الأخيرة
startPage = TotalPage - theOpt.barSize + 1;
endPage = TotalPage;
theOpt.showLast = false;
}
else { //الصفحة الوسطى
startPage = pageIndex - Math.ceil(theOpt.barSize / 2) + 1;
endPage = pageIndex + Math.floor(theOpt.barSize / 2);
}
إذا (totalPage <= (theOpt.barSize * 1.5)) {
theOpt.showLast = theOpt.showFirst = false;
}
}
وظيفة _getLink(الفهرس، النص) {
إذا (! txt) txt = فهرس؛
return "<a href='javascript:;' style='margin: 2px 5px;border: 1px Solid #6d8cad;color: #0269BA;الحشو: 2px 5px;text-decoration: none;' onclick='myPagerChanges[/" " + divPager + "/"](" + Index + ")'>" + txt + "</a>";
}
var barHtml = ""; // شريط الصفحة
barHtml += pageIndex == 1 "" : _getLink(pageIndex - 1, "الصفحة السابقة");
إذا (theOpt.showFirst) {
barHtml += _getLink(1) + "<span>...</span>";
}
لـ (var Index = startPage; Index <= endPage; Index++) {
إذا (الفهرس == فهرس الصفحة) {
barHtml += "<span style='color:red;font-weight:blod; '>" + Index + "</span>";
}
آخر {
barHtml += _getLink(index);
}
}
إذا (theOpt.showLast) {
barHtml += "<span>...</span>" + _getLink(totalPage);
}
barHtml += pageIndex == TotalPage "" : _getLink(pageIndex + 1, "next page");
var gotoHtml = ""; // الانتقال إلى المربع والزر
إذا (theOpt.showGoTo && theOpt.barTemplate.indexOf("{goto}") > 0) {
إذا ((theOpt.autoHideGoTo && TotalPage > 15) || theOpt.autoHideGoTo == false) {
var txtid = divPager + "_goIndex";
var IndexVal = "document.getElementById(/"" + txtid + "/").value";
gotoHtml += "<input type='text' onkeypress='if(event.keyCode==13){myPagerChanges[/"" + divPager + "/"](" + IndexVal + ")}' id='" + txtid + "' value=" + pageIndex + " style='width:30px'>";
gotoHtml += "<input type='button' class='page_bg' value='go' onclick='myPagerChanges[/"" + divPager + "/"](" + IndexVal + ")'>";
}
}
// استبدال القالب
فار pagerHtml = theOpt.barTemplate.replace("{bar}"، barHtml)
.replace("{totalCount}"، TotalCount)
.replace("{pageIndex}"، pageIndex)
.replace("{totalPage}"، TotalPage)
.replace("{goto}"، gotoHtml);
document.getElementById(divPager).innerHTML = pagerHtml;
إرجاع صفحة HTML;
};