The paging function is basically indispensable for website construction. So how to use js to implement simple paging function? For novice or non-experienced programmers, this article's introduction to the implementation of js paging function may be helpful.
js implementation of simple paging code examples are as follows:
1.HTML code:
2.js Code:
$(function(){ var curpage=1;//当前页码 var maxpage = 10;//最大页码 if(maxpage > 1) $("#nextpage").addClass("active"); $("#rowsToshow").change(function(){ console.log($("#rowsToshow").val()); }) $("#prepage").live("click",function(){ curpage = curpage - 1; pageshow(curpage,maxpage); }) $("#nextpage").live("click",function(){ curpage = curpage + 1; pageshow(curpage,maxpage); }) $("#pagecontrol li a").live("click",function(){ curpage = Number($(this).text()); pageshow(curpage,maxpage); }) }) function pageshow(cp,tp){ var sp = cp - 2;//startpage var ep = cp + 2;//endpage var eoff = ep - tp;//tp:totalpage if(eoff>0){ sp = sp - eoff; } if(sp<=0){ ep = ep -sp + 1; } var str = ''; if(cp != 1) str = str + '
[Related article recommendations]
Example of php to achieve paging effect
How to use PHP to implement list paging function
Use PHP to implement simple paging class and its detailed usage
javascript to implement paging function
The above is the detailed content of How to implement simple paging function using js? (code example). For more information, please follow other related articles on the PHP Chinese website!