Home > Web Front-end > JS Tutorial > jquery table paging and other operations implementation code (pagedown, pageup)_jquery

jquery table paging and other operations implementation code (pagedown, pageup)_jquery

WBOY
Release: 2016-05-16 18:29:55
Original
1681 people have browsed it

There is no technical content, let’s start with the picture:
Ideas:
1: Get the button
2: Determine the position of the current table row
jquery table paging and other operations implementation code (pagedown, pageup)_jquery
HTML structure:

Copy code The code is as follows:


firstname:
lastname:
age:
percent:











;input type="checkbox" name="checkbox1"/>





Peter Parker 28 20.9%

John Hood33 25%

Clark Kent 18 44%




style style:


font-family: "Microsoft Yahei";
font-size:12px;
}
table{
text-align:center;
}
th{
height:30px;
border-bottom:1px dashed #ccc;
}
td{
height:30px;
border-bottom:1px dashed #ccc;
}
.bak{
background-color: #ebebeb;
}



js code:


Copy code The code is as follows: $(document).ready(function(){
$("#sure").click(function(){
var fval=$("#firstname").val();
var lval=$("#lastname").val();
var age=$("#age").val() ;
var percent=$("#percent").val();
//Build table
var str='' '' fval '' '' lval '' '' age '< /td>' '' percent '';
$("table").append(str);
str="";
})
//Set the initial tr number
var logo=0;
$(document).keydown(function(e){
var table=$("table tr");
//If pagedown is pressed
if(e.keyCode==40){
//Remove all tr ​​styles
$("tr.bak").removeClass("bak ");
//Highlight the currently pointed tr
$("tr:eq(" logo ")").addClass("bak");
//Add the tr serial number 1
logo;
}
//If the tr sequence number exceeds the length of tr, return the first line;
if(logo>table.length){
logo=0;
}
//If the pageup is pressed
if(e.keyCode==38){
//The tr serial number is reduced by one from the current serial number, which is to move up one position
var l =logo-1;
//If the tr serial number is less than 0, that is, the tr serial number at this time should be at the bottom;
if(l<0){
l=table.length l;//Reset Calculate tr sequence number
}
$("tr.bak").removeClass("bak");
$("tr:eq(" l ")").addClass("bak");
logo=l;//Assign the logo to identify the current tr serial number
}
})
})


Here is the table paging code implemented by jquery. Here are several other table paging implementation methods recommended:
js table paging implementation code

TinyTable javascript table paging and sorting plug-in

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template