/**
maxpage 最大页数
*/
function gotoPage(maxpage)
{
var gotoPage = document.getElementById("currentPage").value;//当前页数
var reg1 = /^\d+$/;
if(gotoPage.match(reg1) == null)
{
alert("请输入正确页码");
return ;
}
else
{
nextpage(maxpage,gotoPage);
}
}
/*
跳转到指定页面
*/
function nextpage(totelpage, currpage)
{
var maxpage=new Number(totelpage);
var curpage=new Number(currpage);
if(curpage<1)
{
alert("没有这一页");
curpage=1;
return ;
}
if(curpage >maxpage )
{
alert("没有这一页");
curpage=maxpage;
return ;
}
document.getElementById("currentPage").value=curpage;
var form = document.pageForm;
form.submit();
}
HTML代码
<tr>
<td colspan="4" align="center" bgcolor="white" height="35" class="td" style="font-weight: 600;">
第${pager.currentPage}页/共${pager.totalPages}页/共${pager.totalRows}条
<a href="javaScript:nextpage('${pager.totalPages}','1');">首页</a>
<a href="javaScript:nextpage('${pager.totalPages}','${pager.currentPage-1}');"> 上一页</a>
<a href="javaScript:nextpage('${pager.totalPages}','${pager.currentPage+1}');"> 下一页</a>
<a href="javaScript:nextpage('${pager.totalPages}','${pager.totalPages}');">尾页</a>
跳转到<input type="text" size="5" value="${pager.currentPage}" name="pager.currentPage" id="currentPage">
<input type="button" onclick="gotoPage('${pager.totalPages}')" value="GO"/>
</td>
</tr>
//Pager.java 类
import java.util.List;
public class Pager<T> {
private int totalRows = 0; // 总行数
private int pageSize = 25; // 每页显示的行数,默认值为10
private int currentPage = 1; // 当前页号
private int totalPages = 0; //总页数
private List<T> results;// 此页查询出的结果
public void setPageInfo(int totalRows){
this.setTotalRows(totalRows);
this.totalPages = totalRows / pageSize + (totalRows % pageSize == 0 ? 0 : 1);
}
public Pager() {
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalPages() {
return totalPages;
}
public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}
public int getTotalRows() {
return totalRows;
}
public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
}
public List<T> getResults() {
return results;
}
public void setResults(List<T> results) {
this.results = results;
}
public boolean canShowFirst() {
if (this.currentPage == 1 || this.totalPages == 0)
return false;
return true;
}
public boolean canShowLast() {
if (this.currentPage == this.totalPages || this.totalPages == 0)
return false;
return true;
}
public boolean canShowPrevious() {
if (this.currentPage == 1 || this.totalPages == 0)
return false;
return true;
}
public boolean canShowNext() {
if (this.currentPage == this.totalPages || this.totalPages == 0)
return false;
return true;
}
}