復制代碼 代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>表格翻頁</TITLE>
<style>
body, td{
font-size: 9pt;
}
a:link {
color: #FF0000;
}
a:visited {
color: #FF0000;
}
a:hover {
color: #006600;
}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
var record = 4;//每頁顯示多少條記錄
var count = 24;//記錄總數
var pageTotal = ((count+record-1)/record)|0;//總頁數
var pagenum = 1;//將要顯示的頁碼
Cookie = {
Set : function (){
var name = arguments[0], value = escape(arguments[1]), days = 365, path = "/";
if(arguments.length > 2) days = arguments[2];
if(arguments.length > 3) path = arguments[3];
with(new Date()){
setDate(getDate()+days);
days=toUTCString();
}
document.cookie = "{0}={1};expires={2};path={3}".format(name, value, days, path);
},
Get : function (){
var returnValue=document.cookie.match(new RegExp("[\b\^;]?" + arguments[0] + "=([^;]*)(?=;|\b|$)","i"));
return returnValue?unescape(returnValue[1]):returnValue;
}
}
String.prototype.format = function(){
var tmpStr = this;
var iLen = arguments.length;
for(var i=0;i<iLen;i++){
tmpStr = tmpStr.replace(new RegExp("\\{" + i + "\\}", "g"), arguments[i]);
}
return tmpStr;
}
function setPagenum(){//整理Cookie
pagenum = Cookie.Get("pagenum");
if(pagenum=="" || pagenum<1){
pagenum=1;
}
}
setPagenum();
//重新整理當前頁碼,如果頁面小於1,則賦值為1,如果大於總頁數,則等於總頁數
coordinatePagenum(pagenum);
//根據當前要顯示的頁碼取得當前面裡第一條記錄的號碼
var pageBegin = (record*(pagenum-1)+1)|0;
//根據當前要顯示的頁碼取得當前面裡最後一條記錄的號碼
var pageEnd = record*pagenum;
function showhiddenRecord(pagenum){
number.innerHTML=pagenum;
if(pagenum<=1){
theFirstPage.innerHTML="第一頁";
thePrePage.innerHTML="上一頁";
}else{
theFirstPage.innerHTML="<a href=\"javascript:firstPage()\">第一頁</a>";
thePrePage.innerHTML="<a href=\"javascript:prePage()\">上一頁</a>";
}
if(pagenum>=pageTotal){
theNextPage.innerHTML="下一頁";
theLastPage.innerHTML="最後一頁";
}else{
theNextPage.innerHTML="<a href=\"javascript:nextPage()\">下一頁</a>";
theLastPage.innerHTML="<a href=\"javascript:lastPage()\">最後一頁</a>";
}
document.getElementById('goto').value=pagenum;
//根據當前要顯示的頁碼取得當前面裡第一條記錄的號碼
pageBegin = (record*(pagenum-1)+1)|0;
//根據當前要顯示的頁碼取得當前面裡最後一條記錄的號碼
pageEnd = record*pagenum;
for(var i=1;i<=count;i++){
if(i>=pageBegin && i<=pageEnd){
mytable.rows[i].style.display="";
}else{
mytable.rows[i].style.display="none";
}
}
Cookie.Set("pagenum", pagenum);
}
function firstPage(){
pagenum=1;
showhiddenRecord(pagenum);
}
function lastPage(){
showhiddenRecord(pageTotal);
}
//重新整理當前頁碼,如果頁面小於1,則賦值為1,如果大於總頁數,則等於總頁數
function coordinatePagenum(num){
if(num<1){
num="1";
}else if(num>pageTotal){
num=pageTotal;
}
}
function prePage(){
pagenum--;
coordinatePagenum(pagenum);
showhiddenRecord(pagenum);
}
function nextPage(){
pagenum++;
coordinatePagenum(pagenum);
showhiddenRecord(pagenum);
}
function gotoPage(num){
coordinatePagenum(pagenum);
showhiddenRecord(num);
}
//-->
</SCRIPT>
</HEAD>
<BODY onLoad="showhiddenRecord(pagenum)">
<center>
共 6 頁 當前第 <span id="number">1</span> 頁
<span id="theFirstPage"><a href="javascript:firstPage()">第一頁</a></span>
<span id="thePrePage"><a href="javascript:prePage()">上一頁</a></span>
<span id="theNextPage"><a href="javascript:nextPage()">下一頁</a></span>
<span id="theLastPage"><a href="javascript:lastPage()">最後一頁</a></span>
轉到第<select onChange="gotoPage(this.value)" name="goto">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
</select>頁
</center>
<TABLE id="mytable" cellpadding=4 cellspacing=1 border=0 bgcolor=#999999 width=500 align=center>
<TR bgcolor=#ffffff><TD>標題</TD></TR>
<TR bgcolor=#ffffff><TD>1</TD></TR>
<TR bgcolor=#ffffff><TD>2</TD></TR>
<TR bgcolor=#ffffff><TD>3</TD></TR>
<TR bgcolor=#ffffff><TD>4</TD></TR>
<TR bgcolor=#ffffff><TD>5</TD></TR>
<TR bgcolor=#ffffff><TD>6</TD></TR>
<TR bgcolor=#ffffff><TD>7</TD></TR>
<TR bgcolor=#ffffff><TD>8</TD></TR>
<TR bgcolor=#ffffff><TD>9</TD></TR>
<TR bgcolor=#ffffff><TD>10</TD></TR>
<TR bgcolor=#ffffff><TD>11</TD></TR>
<TR bgcolor=#ffffff><TD>12</TD></TR>
<TR bgcolor=#ffffff><TD>13</TD></TR>
<TR bgcolor=#ffffff><TD>14</TD></TR>
<TR bgcolor=#ffffff><TD>15</TD></TR>
<TR bgcolor=#ffffff><TD>16</TD></TR>
<TR bgcolor=#ffffff><TD>17</TD></TR>
<TR bgcolor=#ffffff><TD>18</TD></TR>
<TR bgcolor=#ffffff><TD>19</TD></TR>
<TR bgcolor=#ffffff><TD>20</TD></TR>
<TR bgcolor=#ffffff><TD>21</TD></TR>
<TR bgcolor=#ffffff><TD>22</TD></TR>
<TR bgcolor=#ffffff><TD>23</TD></TR>
<TR bgcolor=#ffffff><TD>24</TD></TR>
</TABLE>
</BODY>
</HTML>