부르다:
다음과 같이 코드 코드를 복사합니다.
var pageChange = 함수(색인) {
var html = pager("divid", index, 5, 1000, pageChange, { showGoTo: false, showFirst: false });
}
성취하다:
다음과 같이 코드 코드를 복사합니다.
호출기 = 함수(divPager, pageIndex, pageSize, totalCount, pageChange, opt) {
var theOpt = {
barSize: 5, //페이징 바에 표시되는 페이지 수
barTemplate: "{bar} 총계 {totalPage} 페이지 {totalCount} 항목 {goto}", //템플릿 표시
autoHide: true, //자동으로 숨길지 여부
showFirst: true, //totalPage>barSize일 때 첫 번째 페이지 링크를 자동으로 표시할지 여부
showLast: true, //totalPage>barSize일 때 마지막 페이지 링크를 자동으로 표시할지 여부
showGoTo: true, //GoTo 표시 여부
autoHideGoTo: true //너무 적은 경우 GoTo를 자동으로 숨길지 여부
};
만약 (선택) {
if(opt.barSize)
theOpt.barSize = opt.barSize;
if(opt.barTemplate)
theOpt.barTemplate = opt.barTemplate;
if (opt.autoHide == false)
theOpt.autoHide = 거짓;
if (opt.showFirst == false)
theOpt.showFirst = 거짓;
if (opt.showLast = false)
theOpt.showLast = 거짓;
if (opt.showGoTo == false)
theOpt.showGoTo = 거짓;
if (opt.autoHideGoTo == false)
theOpt.autoHideGoTo = 거짓;
}
var 핸들 = window.myPagerChanges = (함수 (x) { return x; } (window.myPagerChanges || {}));
if (!myPagerChanges[divPager]) myPagerChanges[divPager] = pageChange;
var startPage = 0; //페이징 바의 시작 페이지
var endPage = 0; //페이지 표시줄 끝 페이지
var showFirst = true;
var showLast = true;
if (isNaN(pageIndex)) {
페이지 인덱스 = 1;
}
pageIndex=parseInt(pageIndex);
if (페이지 인덱스 <= 0)
페이지 인덱스 = 1;
if (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 = "";
반품 "";
}
if (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);
}
if (totalPage <= (theOpt.barSize * 1.5)) {
theOpt.showLast = theOpt.showFirst = 거짓;
}
}
함수 _getLink(색인, txt) {
if (!txt) txt = 인덱스;
return "<a href='javascript:;' style='margin: 2px 5px;border: 1px solid #6d8cad;color: #0269BA;padding: 2px 5px;text-꾸밈: none;' onclick='myPagerChanges[/" " + divPager + "/"](" + index + ")'>" + txt + "</a>";
}
var barHtml = ""; //페이지 바
barHtml += pageIndex == 1 ? "" : _getLink(pageIndex - 1, "이전 페이지");
if (theOpt.showFirst) {
barHtml += _getLink(1) + "<span>...</span>";
}
for (var index = startPage; index <= endPage; index++) {
if (색인 == pageIndex) {
barHtml += "<span style='color:red;font-weight:blod; '>" + index + "</span>";
}
또 다른 {
barHtml += _getLink(index);
}
}
if (theOpt.showLast) {
barHtml += "<span>...</span>" + _getLink(totalPage);
}
barHtml += pageIndex == totalPage ? "" : _getLink(pageIndex + 1, "다음 페이지");
var gotoHtml = ""; //상자 및 버튼으로 이동
if (theOpt.showGoTo && theOpt.barTemplate.indexOf("{goto}") > 0) {
if ((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 + ")'>";
}
}
//템플릿 교체
var pagerHtml = theOpt.barTemplate.replace("{bar}", barHtml)
.replace("{totalCount}", totalCount)
.replace("{pageIndex}", 페이지인덱스)
.replace("{totalPage}", totalPage)
.replace("{goto}", gotoHtml);
document.getElementById(divPager).innerHTML = pagerHtml;
pagerHtml을 반환합니다.
};