#macro(pageNavigation $pageInfo $formName ) #if($pageInfo) <div class="pagenumber"> 共有$!pageInfo.totalItem个记录 ## 设置页码宽度,一边pageWidth个 #set($pageWidth = 5) ## 判断是否有上一页,当前页数大于1才有 #if($pageInfo.currentPage > 1) #set($previousPage=${pageInfo.currentPage} - 1) <a href="javascript:gotoPage('$formName', $previousPage);"> < 上一页 </a> #else <span class="disabled"> 上一页 </span> #end ##计算向左快速翻页 #if($pageInfo.currentPage > $pageWidth + 1) #set($quickLeftPage = $pageInfo.currentPage - $pageWidth - 1) <a href="javascript:gotoPage('$formName', $quickLeftPage);">...</a> #end ## 计算最左边的页码 #if($pageInfo.currentPage > $pageWidth) #set ($leftPage=$pageInfo.currentPage - $pageWidth) #else #set ($leftPage = 1) #end ## 计算最右边的页码 #if($pageInfo.currentPage + $pageWidth > $pageInfo.totalPage) #set ($rightPage=$pageInfo.totalPage) #else #set ($rightPage = $pageInfo.currentPage + $pageWidth) #end #if($rightPage < 1) #set ($rightPage = 1) #end ## 显示页码 #foreach( $pageIndex in [$leftPage..$rightPage] ) #if($pageIndex!=$pageInfo.currentPage) <a href="javascript:gotoPage('$formName', $pageIndex);">$pageIndex</a> #else <span class="current">$pageIndex</span> #end #end ##计算向右快速翻页 #if($pageInfo.totalPage > $rightPage) #set ($rightNextPage=$rightPage + $pageWidth + 1) <a href="javascript:gotoPage('$formName', $rightNextPage);">...</a> #end ## 判断是否有下一页,当前页数小于总页数时才有 #if($pageInfo.currentPage < $pageInfo.totalPage) #set($nextPage=${pageInfo.currentPage} + 1) <a href="javascript:gotoPage('$formName', $nextPage);">下一页</a> #else <span class="disabled">下一页 > </span> #end <span class="font_gray_normal" >共$pageInfo.totalPage页 到第 <input type="text" onblur="inputPage('$formName',this)" size="4" class="page_select" /> 页 </span> <input name="" type="button" class="btn_sure" onclick="document.getElementsByName('$formName')[0].submit();" value="" /> </div> <script> function inputPage(formName,obj){ if(obj.value != ""){ gotoPage(formName,obj.value) } } function gotoPage(formName,pageIndex){ if(pageIndex == ""){ alert("请输入页码"); return; } var pageNum1 = pageIndex + ""; var pageNum = 1; var pattern = /^([0-9])+$/; var flag = pattern.test(pageNum1); if(flag){ pageNum = pageNum1; }else{ alert("页码["+pageNum1+"]不正确"); return; } var pageInputName = "currentPage"; var pageInput = null; var form = document.getElementsByName(formName)[0]; if(document.getElementsByName(pageInputName).length != 0){ pageInput = document.getElementsByName(pageInputName)[0]; pageInput.value = pageNum; }else{ pageInput = document.createElement("input"); pageInput.type = "hidden"; pageInput.name = "currentPage"; pageInput.value = pageNum; form.appendChild(pageInput); } form.submit(); } </script> #else <div class="pagenumber">没有分页对象</div> #end #end