<div class="htmlarea"> <textarea id="runcode98560"> <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()\">第一页"; thePrePage.innerHTML="<a href=\"javascript:prePage()\">上一页"; } if(pagenum>=pageTotal){ theNextPage.innerHTML="下一页"; theLastPage.innerHTML="最后一页"; }else{ theNextPage.innerHTML="<a href=\"javascript:nextPage()\">下一页"; theLastPage.innerHTML="<a href=\"javascript:lastPage()\">最后一页"; } 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> <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> </textarea><br><input onclick="runEx('runcode98560')" type="button" value="运行代码"> <input onclick="doCopy('runcode98560')" type="button" value="复制代码"> <input onclick="doSave(runcode98560)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>