JS code to achieve table data paging effect _javascript skills

Source: Internet
Author: User
Tags prev

The first one: a very common and simple Display page page

Effect Chart:

• This is the HTML code, very simple (I seem to have seen the little eyes)

<! DOCTYPE html> 
$ (function () {
var $table =$ (' table ');//Get Table Object
var currentpage=;//set the current page defaults to
var pagesize=;//set the number to display for each page
$table. Bind (' paging ', function () {
$table. Find (' tbody tr '). Hide (). Slice (Currentpage*pagesize, currentpage+) *pagesize). Show ();
Hide all the rows in the Tbody, and then show the data by slice combining the current number of pages and the numbers displayed on the page
});
var sumrows= $table. Find (' tbody tr '). length;//get Data
total
number of rows var sumpages=math.ceil (sumrows/pagesize); var $pager =$ (' <div class= ' page ' ></div> ');
for (var pageindex=;p ageindex<sumpages;pageindex++) {
$ (' <a href= ' # ' ><span> ' + (pageindex+) + ' </span></a> '). Bind ("click", {"NewPage":p ageindex},function (event) {
currentpage=event.data[) NewPage "];
$table. Trigger ("paging");
Add the trigger paging function} for each number of pages to be displayed
. appendto ($pager);
$pager. Append ("");
}
$pager. InsertAfter ($table);
$table. Trigger ("paging");

Second: Implementing the Forward and backward pages

Effect Chart:

• This is all code, with the original JS, still very simple drop (as if the native JS kind of inexplicable love, there are wood)

<! DOCTYPE html> 

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.