<div class="codetitle"> <span><a style="CURSOR: pointer" data="13320" class="copybut" id="copybut13320" onclick="doCopy('code13320')"><u>複製程式碼</u></a></span>如下程式碼:</div> <div class="codebody" id="code13320"> <br>/**<br>* Ajax分頁功能 <br>* 在需要分頁的地方加入<ul class="pagination"> <br>* 作為分頁元件容器元素。 <br>* pageCount 總頁數 <br>* currentPage 目前頁數 <br>* container 帶有pagination類別的ol容器元素 <br>* loadData 用於載入資料的函數 <br>* version 1.0 <br>*/ <br>分頁 : function( pageCount, currentPage, 容器, loadData) { <br>this.startPage = 1; <br>this.endPage = pageCount; <br>this.minDisplayPageCount = 5; <br>var c = $(容器); <br>var paginationLinks = ""; <br>if(pageCount == 1) { <br>c.css({'visibility': 'hidden'}); <br>回傳;<br>} <br>if(pageCount > this.minDisplayPageCount 1) { <br>if(currentPage - this.minDisplayPageCount > 0) { <br>this.startPage = currentPage -this.minDisplayPageCount; <br>} <br>if((currentPage this.minDisplayPageCount - 1) this.endPage = currentPage this.minDisplayPageCount - 1; <br>} else { <br>this.endPage = pageCount; <br>} <br>} <br>paginationLinks = "<ul>"; <br>if(currentPage != 1) { <br>paginationLinks = "<li><a id="prevpage" href="javascript:;" rel="prev">《上一頁</a></li>"; <br>} <br>for(var i = this.startPage; i if(currentPage == i) { <br>paginationLinks = "<li id=' page_" currentPage "_container'><a id='page_" i "' class="current" href="javascript:;">" currentPage "</a></li>"; <br>} else { <br>paginationLinks = "<li id='page_" i "_container'> <a id='page_" i "' href="javascript:;">" 我「</a>」; <br>} <br>} <br>if(currentPage paginationLinks = "</li> <li><a id="nextpage" href="javascript:;" rel="下一頁">下一頁》</a></li>"; <br>} <br>paginationLinks = "</ul>"; <br>c.html(paginationLinks); <br>var links = $("#page_number ul li a"); <br>links.each(function(index) { <br>if(!(this.innerHTML == "上一頁" || this.innerHTML == "下一頁")) { <br>$(this ).click(function(event) { <br>alert(links[index].innerHTML); <br>loadData(curTaskId,"","",parseInt(links[index].innerHTML)); <br>分頁(pageCount, parseInt(links[index].innerHTML), Container, loadData) <br>}); var prevPage = $("#prevpage"); <br>var nextPage = $("#nextpage") ; <br>c.css({'可見性': '可見'}); <br>if(prevPage) { <br>prevPage.click(function(event) { <br>loadData(curTaskId,"", "", currentPage - 1); <br>分頁(pageCount, currentPage - 1,容器,載入資料)<br>}); <br>} <br>if(nextPage) { <br>nextPage.click(function (event) { <br>loadData(curTaskId,"","",currentPage 1) <br>分頁(pageCount, currentPage 1 , 容器, loadData) <br>} <br>} <br><br> <br>load載入資料的函數,函數需要定義一個目前頁數的參數,例如: <br><br> </ul> </div> <br><br> 複製程式碼<div class="codetitle"> <span><a style="CURSOR: pointer" data="5034" class="copybut" id="copybut5034" onclick="doCopy('code5034')"> 程式碼如下:<u> </u> </a>var currentPage = 1; </span>loadExamList(currentPage){ </div>//TODO <div class="codebody" id="code5034">分頁(5,currentPage,$(ul),loadExamList ); <br>}; <br> <br>5是總頁數,1是目前頁數,$(ul)是虛擬頁碼按鈕存放的位置,loadExamList是點選上一頁、下一頁頁或頁碼的呼叫時的函數。</div>