<%@ include file="/WEB-INF/common/pagination.jspf"%>
需要实现pageBO 对象
<%@ page contentType="text/html;charset=GBK"%>
<input type="hidden" name="pageBO.fromPageNum" id="fromPageNum" value="<s:property value="pageBO.fromPageNum"/>">
<input type="hidden" name="pageBO.pageSize" id="rowCountPerPage" value="<s:property value="pageBO.pageSize"/>">
<br/>
<table border="0" cellspacing="0" cellpadding="0" width="800px">
<tr>
<!-- <td height="22" width="200px" align="left" class="txgy14"> </td> -->
<td align="left">
<a id="aFirst" onClick="first(this)" style="cursor:hand">首页</a> |
<a id="aPrevious" onClick="previous(this)" style="cursor:hand">上一页</a> |
<a id="aNext" onClick="next(this)" style="cursor:hand">下一页</a> |
<a id="aLast" onClick="last(this)" style="cursor:hand">尾页</a> |
第 <label id="lbCurPage"><s:property value="pageBO.curPage"/></label> / <label id="lbPageNum"><s:property value="pageBO.lastPage"/></label> 页 |
共 <label id="lbRowNum"><s:property value="pageBO.totalNum"/></label> 条 |
每页 <input type="text" style="height:18" size="3" maxlength="3" id="rowNumPerPage" value="" onKeyUp="beforeDoRow(this)" onBlur="doRow('rowNumPerPage',false)"> 条
|
转到第
<input type="text" style="height:18" size="3" id="pageNO" onKeyUp="beforeDoRow1(this)" οnblur="doJump('pageNO')"> 页
</td>
<td width="10%"> </td>
</tr>
</table>
<script language="javascript">
<s:if test="pageBO == null">
var displayRowCount = 20;//一页显示的记录数,显示用的
var rowCountPerPage = 20;//一页显示的记录数,作为参数后台去
var curPage = 1;//当前页码
var curPage_NotChange = 1;//当前页码,保持页面打开的值不变
var fromPageNum = 1;//当前页面记录起始位置
var lastPage = 1;//最后一页的页码
var rowNum = 1;//总的记录数
</s:if>
<s:else>
var displayRowCount = <s:property value="pageBO.pageSize"/>;//一页显示的记录数,显示用的
var rowCountPerPage = <s:property value="pageBO.pageSize"/>;//一页显示的记录数,作为参数后台去
var curPage = <s:property value="pageBO.curPage"/>;//当前页码
var curPage_NotChange = <s:property value="pageBO.curPage"/>;//当前页码,保持页面打开的值不变
var fromPageNum = <s:property value="pageBO.fromPageNum"/>;//当前页面记录起始位置
var lastPage = <s:property value="pageBO.lastPage"/>;//最后一页的页码
var rowNum = <s:property value="pageBO.totalNum"/>;//总的记录数
</s:else>
function initPagination()
{
rowCountPerPage = displayRowCount;
document.getElementById("fromPageNum").value = fromPageNum;
document.getElementById("rowCountPerPage").value = rowCountPerPage;
document.getElementById("rowNumPerPage").value = displayRowCount;
if (document.getElementById("rowNumPerPage_second") != null) {
document.getElementById("rowNumPerPage_second").value = displayRowCount;
}
if (curPage == lastPage || (lastPage == 0)) {
if (document.getElementById('aNext') != null) {
document.getElementById('aNext').disabled = true;
}
if (document.getElementById('aNext_Second') != null) {
document.getElementById('aNext_Second').disabled = true;
}
if (document.getElementById('aLast') != null) {
document.getElementById('aLast').disabled = true;
}
if (document.getElementById('aLast_Second') != null) {
document.getElementById('aLast_Second').disabled = true;
}
}
if (curPage == 1 || (curPage == 1 && lastPage == 0)) {
if (document.getElementById('aFirst') != null) {
document.getElementById('aFirst').disabled = true;
}
if (document.getElementById('aFirst_Second') != null) {
document.getElementById('aFirst_Second').disabled = true;
}
if (document.getElementById('aPrevious') != null) {
document.getElementById('aPrevious').disabled = true;
}
if (document.getElementById('aPrevious_Second') != null) {
document.getElementById('aPrevious_Second').disabled = true;
}
}
return true;
}
function gotoFirstPageWhenSearch() {
if (document.getElementById('fromPageNum') != null) {
document.getElementById('fromPageNum').value = 0;
}
}
function first(object)
{
if(!object.disabled)
{
if(curPage == 1)
{
alert("已经是第一页");
return;
}
curPage = 1;
setPagination();
pagination(true);
}
}
function previous(object)
{
if(!object.disabled)
{
if(curPage == 1)
{
alert("已经是第一页");
return;
}
curPage--;
setPagination();
pagination(true);
}
}
function next(object)
{
if(!object.disabled)
{
if(curPage == lastPage)
{
alert("已经是最后一页");
return;
}
curPage++;
setPagination();
pagination(true);
}
}
function last(object)
{
if(!object.disabled)
{
if(curPage == lastPage)
{
alert("已经是最后一页");
return;
}
curPage = lastPage;
setPagination();
pagination(true);
}
}
function setPagination()
{
/*
if(curPage >1)
{
aPrevious.disabled = false;
}
else
{
aPrevious.disabled = true;
}
if(curPage<lastPage)
{
aNext.disabled = false;
}
else
{
aNext.disabled = true;
}
*/
}
function beforeDoRow(object)
{
var keycode = event.keyCode;
if (object.id == 'rowNumPerPage') {
if (document.getElementById('rowNumPerPage_second') != null) {
document.getElementById('rowNumPerPage_second').value = object.value;
}
} else if (object.id == 'rowNumPerPage_second') {
document.getElementById('rowNumPerPage').value = object.value;
}
if (keycode == 13)
{
doRow(object.id,true);
}
}
function beforeDoRow1(object)
{
var keycode = event.keyCode;
if (object.id == 'pageNO') {
if (document.getElementById('pageNO_second') != null) {
document.getElementById('pageNO_second').value = object.value;
}
} else if (object.id == 'pageNO_second') {
document.getElementById('pageNO').value = object.value;
}
if (keycode == 13)
{
doJump(object.id);
}
}
function doRow(objectId,needSubmit)
{
//为了屏蔽frmMain的submit按钮
if(isEmpty())
{
return;
}
var rowAmount = document.getElementById(objectId).value;
if(rowAmount==null || rowAmount.length==0)
{
alert("请输入数字");
//document.getElementById(objectId).focus();
return;
}
if(isRowAmount(rowAmount)==false)
{
alert("输入的条数不合法,请重新输入");
//document.getElementById(objectId).focus();
return;
}
if(parseInt(document.getElementById(objectId).value) <= 0)
{
alert("数字必须大于零");
//document.getElementById(objectId).focus();
return;
}
displayRowCount = document.getElementById(objectId).value;
setPagination();
pagination(needSubmit);
}
function doJump(objectId)
{
var rowAmount = document.getElementById(objectId).value;
if(rowAmount == "")
{
alert("没有输入页数,请输入");
//document.getElementById(objectId).focus();
return;
}
if(rowAmount == "0")
{
alert("输入的页数必须大于0");
//document.getElementById(objectId).focus();
return;
}
if(isRowAmount(rowAmount)==false)
{
alert("输入的页数不合法,请重新输入");
//document.getElementById(objectId).focus();
return;
}
//把焦点转移,这样用户就不会因为滚动鼠标中键而再分页
//document.getElementById("rowNumPerPage").focus();
curPage = document.getElementById("pageNO").value;
setPagination();
pagination(true);
}
function pagination(needSubmit)
{
fromPageNum = (curPage-1)*displayRowCount;
if((fromPageNum+1) > rowNum && (!(curPage_NotChange >1&& lastPage==0))) {
alert("输入数字过大,当前页没有可显示的记录!");
//document.getElementById("rowNumPerPage").focus();
return;
}
rowCountPerPage = displayRowCount;
document.getElementById("fromPageNum").value = fromPageNum;
document.getElementById("rowCountPerPage").value = rowCountPerPage;
if (needSubmit == null || needSubmit == true) {
document.forms[0].submit();
}
}
/**
* 校验输入的条数是否合法
*
*/
function isRowAmount( d_int)
{
var checkOK = "0123456789";
var checkStr = d_int;
var allValid = true;
var decPoints = 0;
var ch;
for (var i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
if (i == 0 && ch == '0') {
allValid = false;
break;
}
for (var j = 0; j < checkOK.length; j++)
{
if (ch == checkOK.charAt(j))
{
break;
}
}
if (j == checkOK.length)
{
allValid = false;
break;
}
}
return (allValid);
}
function isEmpty()
{
if (rowNum == 0)
{
alert("没有记录");
return true;
}
return false;
}
setTimeout('initPagination()',1000);
</script>