Window.onload =function () {
var pagesize = 3;//number of records displayed per page
var recondsize = 0;//Total record number
var countpage = 0;//Total Pages
var nowpage= 1;
var users = new Array ()//All records stored
var start = 0; Save the record at the beginning of the current page
var end = 0;//Save the record for the current page
var domusername = $ ("UserName");
var domusersex = $ ("Usersex");
var domuserrole = $ ("userrole");
var domshowusers = $ ("showusers");
var addbtn = $ ("addusers");
Registering Events for buttons
Addbtn.onclick = function () {
Create a User Object
var user = new User (Domusername.value, Domusersex.value,
Domuserrole.value);
Store the user object in an array
Users.push (user);
Recondsize = Users.length; Total number of records obtained
Calculate the total number of pages
Countpage = recondsize% pagesize = = 0? Recondsize/pagesize:math
. ceil (Recondsize/pagesize);
if (Recondsize > PageSize) {//When the total record is greater than the Pagezie train of thought from the back 3 number
start = Recondsize-pagesize;
End=recondsize;
}else{//pagesize start = 1;
start=0;
End=recondsize; The actual number of end= is recondsize
}
Invoke method to display user
Showuser (users,start,end,recondsize,countpage,domshowusers);
}
Get page-related buttons
var firstpage = $ ("FirstPage");
var backPage = $ ("BackPage");
var nextPage = $ ("NextPage");
var lastpage = $ ("LastPage");
Firstpage.onclick = function () {
Nowpage = 1;
if (recondsize<= pagesize && recondsize > 0) {
start = 0;
end = Recondsize;
}else{
start=0;
End=pagesize;
}
Showuser (users,start,end,recondsize,countpage,domshowusers);
}
Backpage.onclick = function () {
Nowpage = nowpage-1;//Re-assign value
if (nowpage<=1) {
nowpage=1;
}
if (recondsize <= pagesize && recondsize > 0) {
start = 0;
end = Recondsize;
}else{
Start= (nowpage-1) *pagesize;
End = (nowpage-1) *pagesize+pagesize;
}
Showuser (users,start,end,recondsize,countpage,domshowusers);
}
Nextpage.onclick = function () {
Nowpage = nowpage+1;//Re-assign value
if (nowpage>=countpage) {
Nowpage=countpage;
}
if (recondsize <= pagesize && recondsize > 0) {
start = 0;
end = Recondsize;
}else{
Start= (nowpage-1) *pagesize;
if ((nowpage-1) *pagesize+pagesize>=recondsize) {
end = Recondsize;
}else{
End = (nowpage-1) *pagesize+pagesize;
}
}
Showuser (users,start,end,recondsize,countpage,domshowusers);
}
Lastpage.onclick = function () {
Nowpage = countpage;//Re-assign value
if (recondsize <= pagesize && recondsize > 0) {
start = 0;
end = Recondsize;
}else{
Start= (nowpage-1) *pagesize;
end = Recondsize;
}
Showuser (users,start,end,recondsize,countpage,domshowusers);
}
}
To create a function function that holds the user object data
function User (name, sex, role) {
THIS.name = name;
This.sex = sex;
This.role = role;
}
function $ (ID) {
return document.getElementById (ID);
}
function Showuser (users,start,end,recondsize,countpage,domshowusers) {
Emptying data
for (var JJ = 0; JJ < domshowUsers.childNodes.length;) {
Domshowusers.removechild (DOMSHOWUSERS.CHILDNODES[JJ]);
}
For Loop added
for (Var i=start;i<end;i++) {
var user = users[i];//Consider
Create a row
var tr = document.createelement ("tr");
Creating columns
var TD1 = document.createelement ("TD");
Create a text node
var td1textnode = document.createTextNode (User.Name);
Text node added to TD
Td1.appendchild (Td1textnode);
Creating columns
var td2 = document.createelement ("TD");
Create a text node
var td2textnode = document.createTextNode (user.sex);
Text node added to TD
Td2.appendchild (Td2textnode);
Creating columns
var td3 = document.createelement ("TD");
Create a text node
var td3textnode = document.createTextNode (user.role);
Text node added to TD
Td3.appendchild (Td3textnode);
To add a column to a row
Tr.appendchild (TD1);
Tr.appendchild (TD2);
Tr.appendchild (TD3);
Add Rows to Tbody
if (Domshowusers.haschildnodes ()) {
Domshowusers.insertbefore (Tr,domshowusers.firstchild)//Add data before last data
}else{
Domshowusers.appendchild (TR);//Add to end
}
}
document.getElementById ("msg"). InnerHTML = "Total: {" + recondsize
+ "} Records, total {" + Countpage + "} page";
}