JSP頁面2種簡單的分頁形式

JSP頁面2種簡單的分頁形式,寫下來以做備忘,歡迎各位建議或批評。第一種使用js,第二種直接用url地址。第一種較好。

第一種形式:

<!--分頁信息展示 start-->
        <div class="page-generation" id="marketingpage"> 
         共${info_totalCount}條數據.    
         <a href="javascript:go('${info_currentPage -1}');">上一頁</a>
         <c:forEach begin="1" end="${info_pageNumShown}" var="tt">
          <c:choose>
           <c:when test="${tt==info_currentPage}">
            <font color="red">${tt}</font>
           </c:when>
           <c:otherwise>
            <a href="javascript:go('${tt }');">${tt}</a>
           </c:otherwise>
          </c:choose>
         </c:forEach>
         <a href="javascript:go('${info_currentPage +1 }');">下一頁</a>
         <a href="javascript:go(${info_pageNumShown });">尾頁</a>
        </div>
<!--分頁信息展示 end-->

 js代碼:

 

<script>
//分頁去向
function go(num)  
{    
	var pageNumShown = '${info_pageNumShown}' ;
	pageNumShown = parseInt(pageNumShown);
	var searchContent = $("#search_result_box_textarea").val();
	if(num<=0)  
	{  
		alert('當前已是首頁');  
		return;  
    }  
	if(num>pageNumShown)  
	{  
		alert('當前已是尾頁');  
		return;  
	}  
	var url = window.location;  
	var pos = String(url).indexOf("pageNum");    //查看是否存在pageNum頁數參數  
	if(pos=="-1")  
	{  
        window.location.replace(url+'?pageNum='+num+"&searchContent="+searchContent) ;   //不存在則添加,值爲所點擊的頁數  
	}  
 	else  
	{  
       	var ui = String(url).substring(0,pos);             
        window.location.replace(ui+'pageNum='+num+"&searchContent="+searchContent);      //存在,則刷新pageNum參數值  
    }  
}   
</script>

 

 

 

第二種形式:

 

<!--分頁信息展示 start-->
        <div class="page-generation" id="marketingpage">
         共${info_totalCount}條數據. 
         <c:if test="${info_currentPage le 1}" var="syy">
          <a title="首頁" href="#">首頁</a>
          <a title="上一頁" href="#">上一頁</a>
         </c:if>
         <c:if test="${!syy}">
          <a title="首頁"
           href="<c:url value='/search.htm?pageNum=1&searchContent=${searchContent}'/>">首頁</a>
          <a title="上一頁"
           href="<c:url value='/search.htm?pageNum=${info_currentPage-1}&searchContent=${searchContent}'/>">上一頁</a>
         </c:if>
         <c:forEach var="pageNo" begin="1" end="${info_pageNumShown}">
          <a href="<c:url value='/search.htm?pageNum=${pageNo}&searchContent=${searchContent}'/>">
           <c:if test="${info_currentPage eq pageNo}" var="rsFy">
            <strong>${pageNo}</strong>
           </c:if> 
           <c:if test="${!rsFy}">
             ${pageNo}
           </c:if>
          </a>
         </c:forEach>
         <c:if test="${info_currentPage ge info_pageNumShown}" var="xyy">
          <a title="下一頁" href="#">下一頁</a>
          <a title="尾頁" href="#">尾頁</a>
         </c:if>
         <c:if test="${!xyy}">
          <a title="下一頁"
           href="<c:url value='/search.htm?pageNum=${info_currentPage+1}'/>">下一頁</a>
          <a title="尾頁"
           href="<c:url value='/search.htm?pageNum=${info_pageNumShown}'/>">尾頁</a>
         </c:if>
        </div>
<!--分頁信息展示 end-->

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章