首頁 >web前端 >js教程 >Javascript表格翻頁效果實現想法及程式碼_javascript技巧

Javascript表格翻頁效果實現想法及程式碼_javascript技巧

WBOY
WBOY原創
2016-05-16 17:24:421305瀏覽
複製程式碼 程式碼如下:




表格翻頁 TITLE> <br><style> <BR>body, td{ <BR>font-size: 9pt; <BR>} <BR>a:link { <BR>color: #FF0000; <BR>} <BR> a:visited { <BR>color: #FF0000; <BR>} <BR>a:hover { <BR>color: #006600; <BR>} <BR></style> <br><script language=" JavaScript"> <BR><!-- <BR>var record = 4;//每頁顯示多少筆記錄<BR>var count = 24;//記錄總數<BR>var pageTotal = ((count record-1 )/record)|0;//總頁數<BR>var pagenum = 1;//將要顯示的頁碼<br><br>Cookie = { <BR>Set : function (){ <BR>var name = arguments[0], value = escape(arguments[1]), days = 365, path = "/"; <BR>if(arguments.length > 2) days = arguments[2]; <BR>if(arguments. length > 3) path = arguments[3]; <BR>with(new Date()){ <BR>setDate(getDate() days); <BR>days=toUTCString(); <BR>} <BR>document .cookie = "{0}={1};expires={2};path={3}".format(name, value, days, path); <BR>}, <BR>Get : function (){ <BR>var returnValue=document.cookie.match(new RegExp("[b^;]?" arguments[0] "=([^;]*)(?=;|b|$)","i" )); <BR>return returnValue?unescape(returnValue[1]):returnValue; <BR>} <BR>} <BR>String.prototype.format = function(){ <BR>var tmpStr = this; <BR>var iLen = arguments.length; <BR>for(var i=0;i<iLen;i ){ <BR>tmpStr = tmpStr.replace(new RegExp("\{" i "\}", "g" ), arguments[i]); <BR>} <BR>return tmpStr; <BR>} <BR>function setPagenum(){//整理Cookie <BR>pagenum = Cookie.Get("pagenum"); <BR>if(pagenum=="" || pagenum<1){ <BR>pagenum=1; <BR>} <BR>} <br><br>setPagenum(); <br><br>//重新整理當前頁碼,如果頁面小於1,則賦值為1,如果大於總頁數,則等於總頁數<BR>coordinatePagenum(pagenum); <br><br>//根據目前要顯示的頁碼取得當前面裡第一筆記錄的號碼<BR>var pageBegin = (record*(pagenum-1) 1)|0; <br><br>//根據目前要顯示的頁碼取得前面裡最後一筆記錄的號碼<BR>var pageEnd = record*pagenum; <br><br>function showhiddenRecord(pagenum){ <BR>number.innerHTML=pagenum; <BR>if(pagenum<=1){ <BR>theFirstPage。頁"; <BR>thePrePage.innerHTML="上一頁"; <BR>}else{ <BR>theFirstPage.innerHTML="<a href="javascript:firstPage()">第一頁" ; <BR>thePrePage.innerHTML="<a href="javascript:prePage()">上一頁"; <BR>} <BR>if(pagenum>=pageTotal){ <BR>theNextPage. innerHTML="下一頁"; <BR>theLastPage.innerHTML="最後一頁"; <BR>}else{ <BR>theNextPage.innerHTML="<a href="javascript:nextPage()">下一頁"; <BR>theLastPage.innerHTML="<a href="javascript:lastPage()">最後一頁"; <BR>} <BR>document.getElementById('goto') .value=pagenum; <BR>//根據目前要顯示的頁碼取得當前面裡第一筆記錄的號碼<BR>pageBegin = (record*(pagenum-1) 1)|0; <br><br> //根據目前要顯示的頁碼取得當前面裡最後一筆記錄的號碼<BR>pageEnd = record*pagenum; <BR>for(var i=1;i<=count;i ){ <BR>if(i >=pageBegin && i<=pageEnd){ <BR>mytable.rows[i].style.display=""; <BR>}else{ <BR>mytable.rows[i].style.display="none" ; <BR>} <BR>} <BR>Cookie.Set("pagenum", pagenum); <BR>} <br><br>function firstPage(){ <BR>pagenum=1; <BR>showhiddenReop( pagenum); <BR>} <br><br>function lastPage(){ <BR>showhiddenRecord(pageTotal); <BR>} <br><br>//重新整理當前頁碼,如果頁面小於1,則賦值為1,若大於總頁數,則等於總頁數<BR>function coordinatePagenum(num){ <BR>if(num<1){ <BR>num="1"; <BR>}else if(num >pageTotal){ <BR>num=pageTotal; <BR>} <BR>} <br><br>function prePage(){ <BR>pagenum--; <BR>coordinatePagenum(pagenum) <BR>pagenum--; <BR>showhiddenPagenum(pagenum); <br>show pagenum); <br>} <BR><BR>function nextPage(){ <BR>pagenum ; <BR>coordinatePagenum(pagenum); <br>showhiddenRecord(pagenum); <br>} <BR><BR><BR> gotoPage(num){ <🎜>coordinatePagenum(pagenum); <🎜>showhiddenRecord(num); <🎜>}<BR>//--> <BR></script> <br> <br><br>
;
共6 頁目前第1
第一頁 span>
上一頁
下一頁
最後一頁
轉到第


















15









表>
身體>

標題
1
2
3
4
5
6
7
8
9
10
11
12
13
14
16
17
18
19
20
21
22
23
24
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn