เรียก:
คัดลอกรหัสรหัสดังต่อไปนี้:
var pageChange = ฟังก์ชั่น (ดัชนี) {
var html = เพจเจอร์ ("แบ่ง", ดัชนี, 5, 1000, เปลี่ยนหน้า, { showGoTo: false, showFirst: false });
-
ทำให้สำเร็จ:
คัดลอกรหัสรหัสดังต่อไปนี้:
เพจเจอร์ = ฟังก์ชั่น (divPager, pageIndex, ขนาดหน้า, TotalCount, เปลี่ยนหน้า, เลือก) {
var theOpt = {
barSize: 5, //จำนวนหน้าที่แสดงในแถบเพจ
barTemplate: "{bar} รวม {totalPage} หน้า {totalCount} รายการ {goto}", // แสดงเทมเพลต
autoHide: true, // ว่าจะซ่อนอัตโนมัติหรือไม่
showFirst: จริง // ว่าจะแสดงลิงค์หน้าแรกโดยอัตโนมัติหรือไม่เมื่อ TotalPage>barSize
showLast: จริง // ว่าจะแสดงลิงก์หน้าสุดท้ายโดยอัตโนมัติหรือไม่เมื่อ TotalPage>barSize
showGoTo: จริง // ไม่ว่าจะแสดง GoTo หรือไม่
autoHideGoTo: true //ถ้ามีน้อยเกินไป ไม่ว่าจะซ่อน GoTo โดยอัตโนมัติหรือไม่
-
ถ้า (เลือก) {
ถ้า(opt.barSize)
theOpt.barSize = opt.barSize;
ถ้า (opt.barTemplate)
theOpt.barTemplate = opt.barTemplate;
ถ้า (opt.autoHide == false)
theOpt.autoHide = เท็จ;
ถ้า (opt.showFirst == เท็จ)
theOpt.showFirst = เท็จ;
ถ้า (opt.showLast = เท็จ)
theOpt.showLast = เท็จ;
ถ้า (opt.showGoTo == เท็จ)
theOpt.showGoTo = เท็จ;
ถ้า (opt.autoHideGoTo == เท็จ)
theOpt.autoHideGoTo = เท็จ;
-
var handles = window.myPagerChanges = (ฟังก์ชั่น (x) { กลับ x; } (window.myPagerChanges || {}));
ถ้า (!myPagerChanges[divPager]) myPagerChanges[divPager] = pageChange;
var startPage = 0; //หน้าเริ่มต้นของแถบเพจ
var endPage = 0; //หน้าท้ายแถบหน้า
var showFirst = จริง;
var showLast = จริง;
ถ้า (isNaN (pageIndex)) {
ดัชนีหน้า = 1;
-
pageIndex = parseInt (เพจดัชนี);
ถ้า (ดัชนีหน้า <= 0)
ดัชนีหน้า = 1;
ถ้า (pageIndex * pageSize > TotalCount) {
pageIndex = Math.ceil (totalCount / ขนาดหน้า);
-
if (totalCount == 0) { //หากไม่มีข้อมูล
document.getElementById(divPager).innerHTML = "";
กลับ "";
-
var TotalPage = Math.ceil(totalCount / ขนาดหน้า);
if (theOpt.autoHide && TotalCount <= ขนาดหน้า) { //ซ่อนอัตโนมัติ
document.getElementById(divPager).innerHTML = "";
กลับ "";
-
ถ้า (totalPage <= theOpt.barSize) {
หน้าเริ่มต้น = 1;
endPage = this.totalPage;
theOpt.showLast = theOpt.showFirst = เท็จ;
-
อื่น {
if (pageIndex <= Math.ceil(theOpt.barSize / 2)) { //สองสามหน้าแรก
หน้าเริ่มต้น = 1;
endPage = theOpt.barSize;
theOpt.showFirst = เท็จ;
-
else if (pageIndex > (totalPage - theOpt.barSize / 2)) { // สองสามหน้าสุดท้าย
startPage = TotalPage - theOpt.barSize + 1;
endPage = หน้ารวม;
theOpt.showLast = เท็จ;
-
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 = เท็จ;
-
-
ฟังก์ชั่น _getLink (ดัชนี, txt) {
ถ้า (!txt) txt = ดัชนี;
return "<a href='javascript:;' style='margin: 2px 5px;border: 1px solid #6d8cad;color: #0269BA;padding: 2px 5px;ข้อความตกแต่ง: none;' onclick='myPagerChanges[/" " + divPager + "/"](" + ดัชนี + ")'>" + txt + "</a>";
-
var barHtml = ""; //แถบหน้า
barHtml += pageIndex == 1 ? "" : _getLink(pageIndex - 1, "หน้าก่อนหน้า");
ถ้า (theOpt.showFirst) {
barHtml += _getLink(1) + "<span>...</span>";
-
สำหรับ (ดัชนี var = startPage; ดัชนี <= endPage; ดัชนี ++) {
ถ้า (ดัชนี == ดัชนีหน้า) {
barHtml += "<span style='color:red;font-weight:blod; '>" + ดัชนี + "</span>";
-
อื่น {
barHtml += _getLink(ดัชนี);
-
-
ถ้า (theOpt.showLast) {
barHtml += "<span>...</span>" + _getLink(totalPage);
-
barHtml += pageIndex == TotalPage ? "" : _getLink(pageIndex + 1, "หน้าถัดไป");
var gotoHtml = ""; //ไปที่กล่องและปุ่ม
ถ้า (theOpt.showGoTo && theOpt.barTemplate.indexOf("{goto}") > 0) {
ถ้า ((theOpt.autoHideGoTo && หน้ารวม > 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 + ")'>";
-
-
//แทนที่เทมเพลต
var pagerHtml = theOpt.barTemplate.replace("{bar}", barHtml)
.replace("{totalCount}", รวมจำนวน)
.replace("{pageIndex}", pageIndex)
.replace("{totalPage}", TotalPage)
.replace("{goto}", gotoHtml);
document.getElementById(divPager).innerHTML = pagerHtml;
กลับเพจเจอร์Html;
-