How to implement simple paging function using js? (code example)

藏色散人
Release: 2018-08-06 17:27:20
Original
4688 people have browsed it

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:

  • 上一页
  • 1
  • 2
  • 3
  • 4
  • 5
  • 下一页
Copy after login

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 + '
  • 上一页
  • ' else str = str + '
    • 上一页
    • ' for(var i= sp;i<=ep;i++){ if(i>0&& i<=tp){ if(i == cp) str = str + '
    • '+i+'
    • '; else str = str + '
    • '+i+'
    • '; } } if(cp != tp) str = str + '
    • 下一页
    '; else str = str + '
  • 下一页
'; $("#pagecontrol").html(str); }
Copy after login

How to implement simple paging function using js? (code example)

[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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!