Page paging is the most familiar to programmers. In web development, page paging is often required. The jquery plug-in jquery pager can easily implement the Javascript paging function, and only a few lines of code are required, javascript paging is easy to handle,Instance EffectFigure below
Instructions for use
The jquery library file and the jquery pager library file must be used (current version 1.1)
Material Preparation
The CSS style file of the page splitter. You can copy the following CSS style and name itPager. CSS
- # Pager ul. Pages {
- Display: block;
- Border: none;
- Text-transform: uppercase;
- Font-size: 10px;
- Margin: 10px 0 50px;
- Padding: 0;
- }
- # Pager ul. Pages Li {
- List-style: none;
- Float: left;
- Border: 1px solid # CCC;
- Text-Decoration: none;
- Margin: 0 5px 0 0;
- Padding: 5px;
- }
- # Pager ul. Pages Li: hover {
- Border: 1px solid # 003f7e;
- }
- # Pager ul. Pages Li. pgempty {
- Border: 1px solid # Eee;
- Color: # Eee;
- }
- # Pager ul. Pages Li. pgcurrent {
- Border: 1px solid # 003f7e;
- Color: #000;
- Font-weight: 700;
- Background-color: # Eee;
- }
Instance code
1. Contains the file section
- <Link href ="Pager.css"Rel =" stylesheet "type =" text/CSS "/>
- <SCRIPT src ="Jquery. js"Type =" text/JavaScript "> </SCRIPT>
- <SCRIPT src ="Jquery. Pager. js"Type =" text/JavaScript "> </SCRIPT>
One CSS style file and two JS library files.
Ii. html Section(The page splitter displays the Div)
- <H1 id = "result"> excellent blog jquery binder
- <Div id ="Pager"> </Div>
Iii. Javascript(Jquery plug-in called by jquery pager)
- <SCRIPT type = "text/JavaScript" Language = "JavaScript">
- $ (Document). Ready (function (){
- $ ("#Pager").Pager({Pagenumber: 1,Pagecount: 15,Buttonclickcallback:Pageclick});
- });
- Pageclick= Function (pageclickednumber ){
- $ ("#Pager"). Pager ({Pagenumber: Pageclickednumber,Pagecount: 15, buttonclickcallback: pageclick
- });
- $ ("#Result"Pai.html (" the current page number of the jquery Browser "+ pageclickednumber +" page ");
- }
- </SCRIPT>
Iv. JavaScript code (called by jquery pager) Analysis
(1) $ ("# pager"). Pager ({}); Part
Pagenumber, indicating the initial page number, such as: 1
Pagecount, indicating the total number of pages, for example, 15
Buttonclickcallback indicates the method called by clicking the page number, for example, pageclick
(2) pageclick = function (pageclickednumber) {}
Pageclick indicates the Function Method for customizing the number of pages to be clicked, such as: function (pageclickednumber ){}
Jquery plug-in jquery pager page splitter only needs the starting page numberPagenumber, Max number of pagesPagecount, Called when the page number is clickedButtonclickcallbackYou can implement the Javascript paging function by using the function method. In actual application, you only need to make a simple modification to the pageclick method. For example, you can set pagenumber and pagecount as variables, you can pass the page value through the get method, and jquery pager can implement the Javascript paging function. Other functions can be expanded on its own. At the same time, you can implement rich dynamic effects for the jquery plug-in jquery pager buttonclickcallback method, for reference
+ ============================================== ========================================================== =====+
The following is the Javascript paging code;
Function pagelist (totalnum, pagesize, curpage, URL) {If (curpage <0) curpage = 0; var maxpage = 0; maxpage = parseint (totalnum + pagesize-1)/pagesize ); maxnum = maxpage; If (curpage> 1) {document. write ('<a href = "' + URL +" 1 "+ '"> homepage </a>'); document. write ('<a href = "' + URL + (curpage-1) + '"> previous page </a>');} var start = 1; var end = 11; if (maxpage <= 11) {end = maxpage;} else {If (curpage> 6) {start = curpage-5; end = start + 10 ;} if (curpage> maxpage-6) {start = maxpage-10; end = maxpage ;}}for (VAR I = start; I <= end; I ++) {if (I = curpage) document. write ('<strong>' + I + '</strong>'); else document. write ('<a href = "' + URL + I + '"> [' + I + '] </a>');} If (curpage <maxnum) {document. write ('<a href = "' + URL + (curpage + 1) + '"> next page </a>'); document. write ('<a href = "' + URL + maxnum + '"> last page </a> ');}}Function pagelist (totalnum, pagesize, curpage, URL) {If (curpage <0) curpage = 0; var maxpage = 0; maxpage = parseint (totalnum + pagesize-1)/pagesize ); maxnum = maxpage; If (curpage> 1) {document. write ('<a href = "' + URL +" 1 "+ '"> homepage </a>'); document. write ('<a href = "' + URL + (curpage-1) + '"> previous page </a>');} var start = 1; var end = 11; if (maxpage <= 11) {end = maxpage;} else {If (curpage> 6) {start = curpage-5; end = start + 10 ;} if (curpage> maxpage-6) {start = maxpage-10; end = maxpage ;}}for (VAR I = start; I <= end; I ++) {if (I = curpage) document. write ('<strong>' + I + '</strong>'); else document. write ('<a href = "' + URL + I + '"> [' + I + '] </a>');} If (curpage <maxnum) {document. write ('<a href = "' + URL + (curpage + 1) + '"> next page </a>'); document. write ('<a href = "' + URL + maxnum + '"> last page </a> ');}}