jquery Paging control Implementation code _jquery

Source: Internet
Author: User

Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<title>jquery Paging Controls </title>
<script src= "Jquery-1.3.min.js" type= "Text/javascript" ></script>

<body>
<div class= "Pager" ></div>
<!--<div>
<select class= "Seid" >
<option>10</option>
<option selected= "Selected" >20</option>
<option>30</option>
</select>
<div class= "First" > Home </div>
<div class= "Pre" > Prev </div>
<div class= "Centerclass" ></div>
<div class= "Next" > next page </div>
<div class= "Last" > final page </div>
<input type= "Text" value= "1"/> of<span class= "Totelspan" >0</span>
</div>-->
</body>

<script type= "Text/javascript" >
var pageindex=1;
var totelsize=60;
var centersize=5;
var pagesize=0;
var totelsec=0;
var outstr= "";
var se= "<select class=\" seid\ ">"
+ "<option>5</option>"
+ "<option selected=\" selected\ ">10</option>"
+ "<option>15</option>"
+ "</select>";
var firstdiv= "<div class=\" first\ "> Home </div>";
var prediv= "<div class=\" pre\ "> Prev </div>";
var centerdiv= "<div class=\" centerclass\ "></div>";
var nextdiv= "<div class=\" next\ "> Next page </div>";
var lastdiv= "<div class=\" last\ "> Last page </div>";
$ ('. Pager '). empty ();
$ ('. Pager '). Append (SE)
$ ('. Pager '). Append (Firstdiv)
$ ('. Pager '). Append (Prediv)
$ ('. Pager '). Append (Centerdiv)
$ ('. Pager '). Append (Nextdiv)
$ ('. Pager '). Append (Lastdiv)
function Pageinit ()
{
var size=0;
var barobj=this;
var pagereinit=function ()
{
pagesize=$ (". Seid option:selected ") [0].innertext;
Size=parseint (Totelsize/pagesize)
var lastsize=totelsize%pagesize;//last page display record
if (lastsize>0)
{
size=size+1;
}
Totelsec=parseint (size/centersize);
The display record for the last section of Var leftsize=size%centersize;//
if (leftsize>0)
{
Totelsec =totelsec+1;
}
Pagebarinit ();
}
var resetpage=function ()
{
Pageindex=1;
pagesize=0;
totelsec=0;
Outstr= "";
}
Alert (' Total pages: ' +size ')
Alert (' Total sector: ' +totelsec ')
Alert (' Number of records per page: ' +pagesize ');
var seclick=function (e)
{
var Selectindex=e.target[e.target.selectedindex].innertext;
Pagesize=parseint (Selectindex);
Alert (' Each page shows: ' +selectindex ');
Resetpage ();
Pagereinit ();
}
var firstclick=function (e)
{
Alert (' Click to Homepage ');
if (pageindex!=1)
{
Pageindex=1;
Alert (' to page 1th ');
}
}
var preclick=function (e)
{
Alert (' Click to previous page ');
if (pageindex!=1)
{
PageIndex =pageindex-1;
Alert (' To the first ' +pageindex+ ' page ');
}
Changecenterbar (pageindex+1);
}
var pageclick=function (e)
{
var targepage=parseint (E.target.innertext);
Pageindex=targepage;
Alert (' Click on ' +targepage+ ' page ');
Changecenterbar (Targepage);
}
var nextclick=function (e)
{
Alert (' Click the next page ');
if (pageindex<size)
{
PageIndex =pageindex+1;
if (pageindex==size)
{
Alert (' to the last page ');
}
else{
Alert (' To the first ' +pageindex+ ' page ');
}
}
Changecenterbar (pageindex-1);
}
var lastclick=function (e)
{
Alert (' Click on the last page ');
if (pageindex<size)
{
Pageindex=size;
Alert (' To the first ' +size+ ' page ');
}
}
var changecenterbar=function (Currentindex)
{
var currentsec=parseint (currentindex/centersize);
if (currentindex%centersize==1)
{
if (currentsec<totelsec)
{Pagebarinit ();}
}
if (currentindex%centersize==0)
{
var currentsec=parseint (currentindex/centersize);
if (currentsec<totelsec)
{Pagebarinit ();}
}
}
var pagebarinit=function ()
{
$('. Seid '). Unbind (' Change ', Seclick);
$ ('. a '). Unbind (' click ', Firstclick);
$ ('. Pre '). Unbind (' click ', Preclick);
$ ('. Next '). Unbind (' click ', Nextclick);
$ ('. Last '). Unbind (' click ', Lastclick);
$('. Seid '). Bind (' Change ', Seclick);
$ ('. I '). bind (' click ', Firstclick);
$ ('. Pre '). Bind (' click ', Preclick);
$ ('. Next '). Bind (' click ', Nextclick);
$ ('. Last '). bind (' click ', Lastclick);
if (size<=centersize)
{
$ ('. Centerclass '). empty ();
for (Var i=1;i<=size;i++)
{
var cdiv= "<span id= ' Page_" +string (i) + "' >" +i+ "</span>";
$ ('. Centerclass '). Append (Cdiv);
$ ("#Page_" +i). Bind (' click ', Pageclick);
}
}else if (size>centersize)
{
$ ('. Centerclass '). empty ();
if (pageindex%centersize==0)
{
var currentsec=parseint (pageindex/centersize);/Current sector
if (currentsec<totelsec)
{
Alert (9)
var startindex= (currentSec-1) *centersize+1;
for (startindex;startindex<=currentsec*centersize;startindex++)
{
Alert (StartIndex)
Alert (' Max ' +currentsec*centersize);
var cdiv= "<span id= ' Page_" +string (startIndex) + "' >" +startindex+ "</span>";
$ ('. Centerclass '). Append (Cdiv);
$ ("#Page_" +startindex). Bind (' click ', Pageclick);
}
}
else if (currentsec==totelsec)
{
var startindex= (currentSec-1) *centersize+1;
for (startindex;startindex<=currentsec*centersize;startindex++)
{
var cdiv= "<span id= ' Page_" +string (startIndex) + "' >" +startindex+ "</span>";
$ ('. Centerclass '). Append (Cdiv);
$ ("#Page_" +startindex). Bind (' click ', Pageclick);
}
}else{
Alert (' paging error ');
}
}else if (pageindex%centersize>0)
{
var currentsec=parseint (pageindex/centersize) +1;//Current sector
if (currentsec<totelsec)
{
var startindex= (currentSec-1) *centersize+1;
For (startindex;startindex<= (currentSec-1) *centersize+centersize); startindex++)
{
var cdiv= "<span id= ' Page_" +string (startIndex) + "' >" +startindex+ "</span>";
$ ('. Centerclass '). Append (Cdiv);
$ ("#Page_" +startindex). Bind (' click ', Pageclick);
}
}
else if (currentsec==totelsec) {
var startindex= (currentSec-1) *centersize+1;
For (startindex;startindex<= (currentSec-1) *centersize +size%centersize); startindex++)
{
var cdiv= "<span id= ' Page_" +string (startIndex) + "' >" +startindex+ "</span>";
$ ('. Centerclass '). Append (Cdiv);
$ ("#Page_" +startindex). Bind (' click ', Pageclick);
}
}else
{
Alert (' paging error ');
}
}
}
}
Pagereinit ();
}
Pageinit ();
</script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.