javascript分页
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript分页相关的知识,希望对你有一定的参考价值。
function f_showPage() {
var pagehtml = ‘‘;
if (currentGroup > 0) {
pageHtml = pageHtml
+ "<a href=‘javascript:gridMainPreGroup()‘><<</a> ";
}
else
{
pageHtml = pageHtml
+ "<a><<</a> ";
}
if (currentPage > 1) {
pageHtml = pageHtml
+ "<a href=‘javascript:gridMainPrePage()‘><</a>"
}
else
{
pageHtml = pageHtml
+ "<a><</a> ";
}
var pageNum = currentGroup * 9 + 1;
for ( var i = 0; i < 9; i++) {
if (pageNum == currentPage) {
pageHtml = pageHtml
+ "<a class=\"current\" href=‘javascript:gridMainChangePage("
+ pageNum + ")‘>" + pageNum + "</a>"
} else {
pageHtml = pageHtml
+ "<a href=‘javascript:gridMainChangePage("
+ pageNum + ")‘>" + pageNum + "</a>"
}
pageNum++;
}
pageHtml = pageHtml
+ "<a href=‘javascript:gridMainNextPage()‘>></a>"
pageHtml = pageHtml
+ "<a href=‘javascript:gridMainNextGroup()‘>>></a>"
$("#page").html(pageHtml);
}
function f_showBadPage() {
var pageHtml = ‘‘;
pageHtml = pageHtml
+ "<a><<</a> ";
pageHtml = pageHtml
+ "<a><</a> ";
var pageNum = currentGroup * 9 + 1;
for ( var i = 0; i < 9; i++) {
if (pageNum == currentPage) {
pageHtml = pageHtml
+ "<a class=\"current\">" + pageNum + "</a>"
} else {
pageHtml = pageHtml
+ "<a>" + pageNum + "</a>"
}
pageNum++;
}
pageHtml = pageHtml
+ "<a>></a>"
pageHtml = pageHtml
+ "<a>>></a>"
$("#page").html(pageHtml);
}
function gridMainPreGroup() {
if(currentGroup > 0)
{
lastGroup = currentGroup;
lastPage = currentPage;
currentGroup = currentGroup - 1;
currentPage = currentGroup * 9 + 1;
}
f_showBadPage();
var parms = gridMain.get(‘parms‘);
parms.page = currentPage;
parms.pagesize = 30;
gridMain.set(‘parms‘, parms);
gridMain.loadData();
}
function gridMainPrePage() {
lastGroup = currentGroup;
lastPage = currentPage;
currentPage = currentPage - 1;
if (currentPage < currentGroup * 9 + 1) {
if (currentGroup > 0) {
currentGroup = currentGroup - 1;
}
}
f_showBadPage();
var parms = gridMain.get(‘parms‘);
parms.page = currentPage;
parms.pagesize = 30;
gridMain.set(‘parms‘, parms);
gridMain.loadData();
}
function gridMainChangePage(page) {
lastGroup = currentGroup;
lastPage = currentPage;
currentPage = page;
f_showBadPage();
var parms = gridMain.get(‘parms‘);
parms.page = currentPage;
parms.pagesize = 30;
gridMain.set(‘parms‘, parms);
gridMain.loadData();
}
function gridMainNextGroup() {
lastGroup = currentGroup;
lastPage = currentPage;
currentGroup = currentGroup + 1;
currentPage = currentGroup * 9 + 1;
f_showBadPage();
var parms = gridMain.get(‘parms‘);
parms.page = currentPage;
parms.pagesize = 30;
gridMain.set(‘parms‘, parms);
gridMain.loadData();
}
function gridMainNextPage() {
lastGroup = currentGroup;
lastPage = currentPage;
currentPage = currentPage + 1;
if (currentPage > currentGroup * 9 + 9) {
currentGroup = currentGroup + 1;
}
f_showBadPage();
var parms = gridMain.get(‘parms‘);
parms.page = currentPage;
parms.pagesize = 30;
gridMain.set(‘parms‘, parms);
gridMain.loadData();
}
以上是关于javascript分页的主要内容,如果未能解决你的问题,请参考以下文章
VSCode自定义代码片段12——JavaScript的Promise对象