Pure JS write pagination (the algorithm has entangled me) __ static function

Source: Internet
Author: User
Tags diff
$ (function () {
Next page
$ ("#nextPage"). Click (function () {
Tablermove ();
var Curr = $ ("#CurrentPage"). attr ("value");
var Newcurr = number (Curr); Current page
var max = $ ("#MaxPage"). attr ("value");
var Newmax = number (max); Maximum page number
if (Newcurr >= Newmax) {
Newcurr = 1;
} else {
Newcurr = Newcurr + 1;
}
$ ("#CurrentPage"). Val (Newcurr);
if ($ ("#pagercss")!= null && $ ("#pagercss")!= "undefined") {
Getpagecss ({currpage:newcurr});
}
Gopage ();
});
Previous page
$ ("#prevPage"). Click (function () {
Tablermove ();
var Curr = $ ("#CurrentPage"). attr ("value");
var Newcurr = number (Curr);
if (Newcurr = = 1) {
var max = $ ("#MaxPage"). attr ("value");
var Newmax = number (max);
Newcurr = max;
} else {
Newcurr = newCurr-1;
}
$ ("#CurrentPage"). Val (Newcurr);
if ($ ("#pagercss")!= null && $ ("#pagercss")!= "undefined") {
Getpagecss ({currpage:newcurr});
}
Gopage ();

});
First page
$ ("#firstPage"). Click (function () {
Tablermove ();
var newcurr = 1;
$ ("#CurrentPage"). Val (Newcurr);
if ($ ("#pagercss")!= null && $ ("#pagercss")!= "undefined") {
Getpagecss ({currpage:newcurr});
}
Gopage ();
});

Last
$ ("#lastPage"). Click (function () {
Tablermove ();
var Curr = $ ("#MaxPage"). attr ("value");
var Newcurr = number (Curr);

$ ("#CurrentPage"). Val (Newcurr);

if ($ ("#pagercss")!= null && $ ("#pagercss")!= "undefined") {
Getpagecss ({currpage:newcurr});
}
Gopage ();
});
});
function Gopage () {
var formData = $ ("#pagerForm"). Serialize ();
var type = $ ("#PagerType"). Val ();
Switch (type) {
Case "1": PagerType1 (FormData); Break
Case "2": PagerType2 (FormData); Break
Case "3": PagerType3 (FormData); Break
Case "4": PagerType4 (FormData); Break
Case "5": PagerType5 (FormData); Break
Case "6": PagerType6 (FormData); Break
Case "7": PagerType7 (FormData); Break
Case "8": PagerType8 (FormData); Break
Default:pagertype1 (FormData);
}
Paging
$.ajax ({
Type: "POST",
Url:pagerurl + "? tick=" + New Date (). Getmilliseconds (),
Data:formdata,
Cache:false,
DataType: "JSON",
Success:function (data) {
Commjson.pagersync (data);
}
});

}

Generate page numbering styles
function Getpagecss (pagerdata) {
var Curr = Pagerdata.currpage | | 1; Current
var maxpage = $ ("#MaxPage"). Val ();
var max = Pagerdata.maxpage | | Number (maxpage); Maximum pages
var diff = Pagerdata.pagerdiffence | | 2; Page difference
var show = Pagerdata.showpage | | 5; Show pages
var start = (Curr-diff) > 0? (Curr + diff > Max max-show + 1:curr-diff): 1; Start Page
var end = start + Show > Max? Max + 1:start + show; End pages
if (Max < show) {//maximum pages less than display pages
for (var i = 1; i < Max; i++) {
if (Curr = = i) {
html + + ' <a style= ' color:red; "href=" javascript:void (0) "class=" pagebtn "> ' + i + ' </a> ';
} else {
html + + ' <a href= ' javascript:void (0) "class=" pagebtn "> ' + i + ' </a> ';
}
}
}
else if (Curr-diff < 0) {//current-page Difference <0
for (var i = start, I < end; i++) {
if (Curr = = i) {
html + + ' <a style= ' color:red; "href=" javascript:void (0) "class=" pagebtn "> ' + i + ' </a> ';
} else {
html + + ' <a href= ' javascript:void (0) "class=" pagebtn "> ' + i + ' </a> ';
}
}
Stitching Next Last Page
}
else if (Curr + show-1 > Max) {//Current page + Display page -1> maximum page number
Stitching Home Previous Page
for (var i = start, I < end; i++) {
if (Curr = = i) {
html + + ' <a style= ' color:red; "href=" javascript:void (0) "class=" pagebtn "> ' + i + ' </a> ';
} else {
html + + ' <a href= ' javascript:void (0) "class=" pagebtn "> ' + i + ' </a> ';
}
}

} else {
Stitching Home Previous Page
for (var i = start, I < end; i++) {
if (Curr = = i) {
html + + ' <a style= ' color:red; "href=" javascript:void (0) "class=" pagebtn "> ' + i + ' </a> ';
} else {
html + + ' <a href= ' javascript:void (0) "class=" pagebtn "> ' + i + ' </a> ';
}
}
Stitching Next Last Page
}
$ ("#pagercss"). HTML (HTML);
}
$ (". Pagebtn"). Die (). Live ("Click", Function () {
Tablermove ();
var Newcurr = number ($ (this). text ());
$ ("#CurrentPage"). Val (Newcurr);
Getpagecss ({currpage:newcurr});
Gopage ();
});

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.