Javascript table page turning effect of the concrete implementation

  • 2020-03-26 21:22:46
  • OfStack

There are many ways to turn the page of the table, the following js as an example for you to detail the specific implementation of the table page effect.
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<HEAD> 
<TITLE> Form page ---www.jb51.net</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;//How many records are displayed per page
var count = 24;//The total number of records
var pageTotal = ((count+record-1)/record)|0;//Total number of pages
var pagenum = 1;//The page number to be displayed


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(){//Arrange the Cookie
pagenum = Cookie.Get("pagenum"); 
if(pagenum=="" || pagenum<1){ 
pagenum=1; 
} 
} 

setPagenum(); 

// Rearrange the current page number if the page is less than 1 , then the value is 1 If it's greater than the total number of pages, it's equal to Total number of pages
coordinatePagenum(pagenum); 

//Gets the number of the first record in the current face based on the current page number to display
var pageBegin = (record*(pagenum-1)+1)|0; 

//Gets the number of the last record in the current face based on the current page number to display
var pageEnd = record*pagenum; 

function showhiddenRecord(pagenum){ 
number.innerHTML=pagenum; 
if(pagenum<=1){ 
theFirstPage.innerHTML=" The first page "; 
thePrePage.innerHTML=" The previous page "; 
}else{ 
theFirstPage.innerHTML="<a href="javascript:firstPage()"> The first page </a>"; 
thePrePage.innerHTML="<a href="javascript:prePage()"> The previous page </a>"; 
} 
if(pagenum>=pageTotal){ 
theNextPage.innerHTML=" The next page "; 
theLastPage.innerHTML=" The last page "; 
}else{ 
theNextPage.innerHTML="<a href="javascript:nextPage()"> The next page </a>"; 
theLastPage.innerHTML="<a href="javascript:lastPage()"> The last page </a>"; 
} 
document.getElementById('goto').value=pagenum; 
//Gets the number of the first record in the current face based on the current page number to display
pageBegin = (record*(pagenum-1)+1)|0; 

//Gets the number of the last record in the current face based on the current page number to display
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); 
} 

// Rearrange the current page number if the page is less than 1 , then the value is 1 If it's greater than the total number of pages, it's equal to Total number of pages
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> 
 A total of  6  page   The current first  <span id="number">1</span>  page  
<span id="theFirstPage"><a href="javascript:firstPage()"> The first page </a></span> 
<span id="thePrePage"><a href="javascript:prePage()"> The previous page </a></span> 
<span id="theNextPage"><a href="javascript:nextPage()"> The next page </a></span> 
<span id="theLastPage"><a href="javascript:lastPage()"> The last page </a></span> 
 Turn to the first <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> page  
</center> 

<TABLE id="mytable" cellpadding=4 cellspacing=1 border=0 bgcolor=#999999 width=500 align=center> 
<TR bgcolor=#ffffff><TD> The title </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> 

Related articles: