思路:

1.讲表格内容存入一个变量

2.通过点击按钮从表格中调取数据

3.讲调取的数据填入表格中

表格分页

html,body {

margin:0;

height:100%;

}

.barcon {

width:auto;

margin:0 auto;

text-align:center;

}

.barcon1 {

font-size:17px;

float:left;

margin-top:20px;

}

.barcon2 {

float:right;

}

.barcon2 ul {

margin:20px 0;

padding-left:0;

list-style:none;

text-align:center;

}

.barcon2 li {

display:inline;

}

.barcon2 a {

font-size:16px;

font-weight:normal;

display:inline-block;

padding:5px;

padding-top:0;

color:black;

border:1px solid #ddd;

background-color:#fff;

}

.barcon2 a:hover {

background-color:#eee;

}

.ban {

opacity:.4;

}

#shade {

background:#000;

filter:alpha(opacity=50);/* IE的透明度*/

opacity:0.5;/* 透明度*/

display:none;

position:absolute;

top:0px;

left:0px;

width:100%;

height:100%;

z-index:9999;/* 此处的图层要大于页面*/

display:none;

}

ID菜单链接地址父菜单

  • 首页
  • 上一页
  • 下一页
  • 尾页
  • 跳转

var table;

table = [

{

"id":"21",

"name":"演唱会",

"parent_id":"15",

"url":"http://www.acfun.cn/v/list99/index.htm/v/list140/index.htm"

},

{

"id":"22",

"name":"舞蹈·彼女",

"parent_id":"0",

"url":"http://www.acfun.cn/v/list123/index.htm"

},

{

"id":"23",

"name":"宅舞",

"parent_id":"22",

"url":"http://www.acfun.cn/v/list134/index.htm"

},

{

"id":"24",

"name":"综合舞蹈",

"parent_id":"22",

"url":"http://www.acfun.cn/v/list135/index.htm"

},

{

"id":"25",

"name":"爱豆",

"parent_id":"22",

"url":"http://www.acfun.cn/v/list129/index.htm"

},

{

"id":"26",

"name":"手作",

"parent_id":"22",

"url":"http://www.acfun.cn/v/list130/index.htm"

},

{

"id":"27",

"name":"造型",

"parent_id":"22",

"url":"http://www.acfun.cn/v/list127/index.htm"

},

{

"id":"28",

"name":"游戏",

"parent_id":"0",

"url":"http://www.acfun.cn/v/list59/index.htm"

},

{

"id":"29",

"name":"主机单机",

"parent_id":"28",

"url":"http://www.acfun.cn/v/list84/index.htm"

},

{

"id":"30",

"name":"游戏集锦",

"parent_id":"28",

"url":"http://www.acfun.cn/v/list83/index.htm"

},

{

"id":"31",

"name":"电子竞技",

"parent_id":"28",

"url":"http://www.acfun.cn/v/list145/index.htm"

},

{

"id":"32",

"name":"英雄联盟",

"parent_id":"28",

"url":"http://www.acfun.cn/v/list85/index.htm"

},

{

"id":"33",

"name":"守望先锋",

"parent_id":"28",

"url":"http://www.acfun.cn/v/list170/index.htm"

},

{

"id":"34",

"name":"桌游卡牌",

"parent_id":"28",

"url":"http://www.acfun.cn/v/list165/index.htm/"

},

{

"id":"35",

"name":"Mugen",

"parent_id":"28",

"url":"http://www.acfun.cn/v/list72/index.htm/"

},

{

"id":"36",

"name":"游戏中心",

"parent_id":"28",

"url":"http://www.acfun.cn/gamecenter"

},

{

"id":"37",

"name":"娱乐",

"parent_id":"0",

"url":"http://www.acfun.cn/v/list59/index.htm"

},

{

"id":"38",

"name":"生活娱乐",

"parent_id":"37",

"url":"http://www.acfun.cn/v/list84/index.htm"

},

{

"id":"39",

"name":"鬼畜调教",

"parent_id":"37",

"url":"http://www.acfun.cn/v/list83/index.htm"

},

{

"id":"40",

"name":"萌宠",

"parent_id":"37",

"url":"http://www.acfun.cn/v/list145/index.htm"

},

{

"id":"41",

"name":"美食",

"parent_id":"37",

"url":"http://www.acfun.cn/v/list85/index.htm"

},

{

"id":"42",

"name":"科技",

"parent_id":"0",

"url":"http://www.acfun.cn/v/list59/index.htm"

},

{

"id":"43",

"name":"科学技术",

"parent_id":"42",

"url":"http://www.acfun.cn/v/list84/index.htm"

},

{

"id":"44",

"name":"教程",

"parent_id":"42",

"url":"http://www.acfun.cn/v/list83/index.htm"

},

{

"id":"45",

"name":"数码",

"parent_id":"42",

"url":"http://www.acfun.cn/v/list145/index.htm"

},

{

"id":"46",

"name":"广告",

"parent_id":"42",

"url":"http://www.acfun.cn/v/list85/index.htm"

},

{

"id":"47",

"name":"影视",

"parent_id":"0",

"url":"http://www.acfun.cn/v/list59/index.htm"

},

{

"id":"48",

"name":"国产剧",

"parent_id":"47",

"url":"http://www.acfun.cn/v/list84/index.htm"

},

{

"id":"49",

"name":"网络剧",

"parent_id":"47",

"url":"http://www.acfun.cn/v/list83/index.htm"

},

{

"id":"50",

"name":"纪录片",

"parent_id":"47",

"url":"http://www.acfun.cn/v/list145/index.htm"

},

{

"id":"51",

"name":"综艺",

"parent_id":"47",

"url":"http://www.acfun.cn/v/list85/index.htm"

},

{

"id":"52",

"name":"文章",

"parent_id":"0",

"url":"http://www.acfun.cn/v/list59/index.htm"

},

{

"id":"53",

"name":"游记·涂鸦",

"parent_id":"52",

"url":"http://www.acfun.cn/v/list84/index.htm"

},

{

"id":"54",

"name":"综合",

"parent_id":"52",

"url":"http://www.acfun.cn/v/list83/index.htm"

},

{

"id":"55",

"name":"工作·情感",

"parent_id":"52",

"url":"http://www.acfun.cn/v/list145/index.htm"

},

{

"id":"56",

"name":"动漫文化",

"parent_id":"52",

"url":"http://www.acfun.cn/v/list85/index.htm"

},

{

"id":"57",

"name":"漫画·文学",

"parent_id":"52",

"url":"http://www.acfun.cn/v/list170/index.htm"

}

]

starpag();

function starpag() {

goPage(1,20);

var tempOption ="";

for (var i =1;i <=totalPage;i++) {

tempOption +='' +i +''

}

$("#jumpWhere").html(tempOption);

};

// 分页函数

// pno--页数

// psize--每页显示记录数

// 分页部分是从真实数据行开始,因而存在加减某个常数,以确定真正的记录数

// 纯js分页实质是数据行全部加载,通过是否显示属性完成分页功能

var pageSize =0;//每页显示行数

var currentPage_ =1;//当前页全局变量,用于跳转时判断是否在相同页,在就不跳,否则跳转。

var totalPage;//总页数

function goPage(pno, psize) {

var num =table.length;//表格所有行数(所有记录数)

pageSize = psize;//每页显示行数

//总共分几页

if (num /pageSize >parseInt(num /pageSize)) {

totalPage =parseInt(num /pageSize) +1;

}else {

totalPage =parseInt(num /pageSize);

}

var currentPage = pno;//当前页数

currentPage_ =currentPage;

var startRow = (currentPage -1) *pageSize +1;

var endRow =currentPage *pageSize;

endRow = (endRow >num) ?num :endRow;

// console.log(endRow);

var tablepag =new Array();

for (let index =startRow;index <=endRow;index++) {

tablepag.push(table[index -1])

}

tabletr(tablepag);

var tempStr ="共" +num +"条记录 共分" +totalPage +"页 当前第" +currentPage +"页";

document.getElementById("barcon1").innerHTML =tempStr;

if (currentPage >1) {

$("#firstPage").on("click",function () {

goPage(1, psize);

}).removeClass("ban");

$("#prePage").on("click",function () {

goPage(currentPage -1, psize);

}).removeClass("ban");

}else {

$("#firstPage").off("click").addClass("ban");

$("#prePage").off("click").addClass("ban");

}

if (currentPage

$("#nextPage").on("click",function () {

goPage(currentPage +1, psize);

}).removeClass("ban");

$("#lastPage").on("click",function () {

goPage(totalPage, psize);

}).removeClass("ban");

}else {

$("#nextPage").off("click").addClass("ban");

$("#lastPage").off("click").addClass("ban");

}

$("#jumpWhere").val(currentPage);

}

function jumpPage() {

var num =parseInt($("#jumpWhere").val());

if (num !=currentPage_) {

goPage(num,pageSize);

}

}

function tabletr(arr) {

var htm ='';

for (let index =0;index < arr.length;index++) {

htm +='

' +

'

' + arr[index].id +'' +

'

' + arr[index].name +'' +

'

' + arr[index].url +'' +

'

' + arr[index].parent_id +'' +

'

' +

'

';

}

$("#list").html(htm);

}

html中table表格分页,纯JS实现表格分页相关推荐

  1. 动态增删表格行(纯JS写法)

    动态增删表格行(纯JS写法) 归档 进行表格下行的动态增加与删除 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional// ...

  2. php对表格的处理,JavaScript_js处理表格对table进行修饰,js处理表格 1、行颜色间隔显示 - phpStudy...

    js处理表格对table进行修饰 js处理表格 1.行颜色间隔显示 css样式:两个选择器 .one{ background-color:#33ffcc; } .two{ backgound-colo ...

  3. css表格排序,纯CSS实现表格排序-利用CSS 变量和Flexbox

    1.引子 今天闲逛知名前端资讯站Front-End Front,发现一个比较有意思的效果,给大家分享下,希望可以对大家有所启发. 纯CSS实现表格排序 心急的同学,先看效果,我放在codepen上. ...

  4. html怎么写分页ajax,js实现ajax分页完整实例

    本文实例讲述了js实现ajax分页的方法.分享给大家供大家参考,具体如下: /p> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transition ...

  5. html中table整体缩小,html-如何缩小表格样式中的间隙?

    您可以使用border-collapse:在表格中折叠. The border-collapse CSS property selects a table's border model. This h ...

  6. html一个页面分页代码怎么写,纯JS前端实现分页代码

    先给大家展示下效果图,如果大家感觉效果不错,请参考实现代码: 因为这是我自己第一次动手用js写分页,写的应该也不是很完美,有些公共的没有抽取出来,但是用起来还是可以的,这块代码是可以把它当做公共的分页 ...

  7. html css分页特效,js css自定义分页效果

    网上看了好多分页插件都不太满意,所以根据网上的一些东西自己做了一个,可以搭配mvc和数据库 效果图片 先来css(样式不喜欢的话可以不用这个) .pagelist {padding:10px 0; t ...

  8. html js 动态表格数据,HTML+JS动态表格

    1. 设置固定列 ID日期星期 propName -- 属性名 valCalc -- 设置值时, 特定回调函数 2. 动态生成可变列 这里模拟服务器获取数据 // 返回数据的格式: /* { poin ...

  9. 纯js分页代码(简洁实用)

    纯js分页代码(简洁实用) 纯js写的分页代码. 复制代码代码如下: //每页显示字数 PageSize=5000; //分页模式 flag=2;//1:根据字数自动分页 2:根据[NextPage] ...

最新文章

  1. 基于Python, Selenium, Phantomjs无头浏览器访问页面
  2. 换「猪心」9天,美国57岁男子能下地走路了!
  3. 剑指offer三:从尾到头打印链表
  4. 驾驶卡丁车 模拟,迷宫(女赛)
  5. 常见HTTP状态(304,200等)
  6. Windows 7备份、还原功能详解
  7. 大表与大表join数据倾斜_技术分享|大数据技术初探之Spark数据倾斜调优
  8. python某公司为员工发放奖品_python 练习2
  9. PHP 文件打开/读取
  10. android 手机本地目录,Android系统的手机文件夹目录详解
  11. duilib列表list使用方法
  12. PS的工具介绍和使用方法
  13. 飞机选座——附:东航320选坐攻略
  14. 男人一生的四菜一汤(转载)
  15. 大数据资源争夺战此起彼伏,对用户而言是福是祸
  16. 计算机维修分为那两种,计算机二级维修中最常见的三种方法是什么?
  17. ef core连接Oracle数据库
  18. 如何有效实现软件的需求管理 - 1
  19. brooks levitate_超越Boost的脚感: Brooks Levitate2体验
  20. 数字大小写转换:如何把“0123456789”转换成“零一二三四五六七八九”?

热门文章

  1. 硬币找零问题的动态规划实现
  2. 【转】细说linux挂载。mount。。。
  3. C# 未找到类型“***”上的构造函数异常原因
  4. 面试题9:AJAX是什么【JS】
  5. win10 家庭中文版没有Hyper-V选项
  6. 去除map中的undefined
  7. 财务RPA是如何帮助CFO成为优质管理者
  8. 【搜集】AVI解码器下载(AE导入avi时报错的解决办法)
  9. 仓库管理系统————QT+SQLite实现
  10. 科普贴 印度(农村)生活