javascript实现json页面分页实例代码
时间:2024-02-25 09:38:56
下午有个朋友问json 数据怎么分页 就捣鼓了一个东东出来
下面直接代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
var a={"code":1,"list":[{"category1_id":"1","category1_name":"\u9152\u6c34\u996e\u6599","category1_intro":"\u6e05\u51c9\u53ef\u53e3\u7684\u9152\u6c34\u996e\u6599","category1_images":"http:\/\/www.songcuomen.com\/attachments\/productType\/2014-01\/10\/21_1389343628.jpg"},{"category1_id":"2","category1_name":"\u7c73\u9762\u7cae\u6cb9","category1_intro":"\u5bb6\u5ead\u5fc5\u5907","category1_images":"http:\/\/www.songcuomen.com\/attachments\/productType\/2014-01\/10\/21_1389343865.jpg"},{"category1_id":"3","category1_name":"\u7f8e\u5bb9\u6d17\u62a4","category1_intro":"\u62a4\u80a4\u5fc5\u5907","category1_images":"http:\/\/www.songcuomen.com\/attachments\/productType\/2014-01\/10\/21_1389343935.jpg"},{"category1_id":"4","category1_name":"\u6e05\u6d01\u6d17\u6da4","category1_intro":"\u7ed9\u60a8\u4e00\u4e2a\u5e72\u51c0\u7684\u751f\u6d3b\u73af\u5883","category1_images":"http:\/\/www.songcuomen.com\/attachments\/productType\/2014-01\/10\/21_1389343986.jpg"},{"category1_id":"5","category1_name":"\u751f\u6d3b\u7528\u54c1","category1_intro":"\u5bb6\u5ead\u5fc5\u5907","category1_images":"http:\/\/www.songcuomen.com\/attachments\/productType\/2014-01\/10\/21_1389344445.jpg"},{"category1_id":"6","category1_name":"\u4f11\u95f2\u98df\u54c1","category1_intro":"\u597d\u5403\u7f8e\u5473","category1_images":"http:\/\/www.songcuomen.com\/attachments\/productType\/2014-01\/10\/21_1389344494.jpg"}]};
var y=1;//表示页数
var t=2;//表示每页现实几条数据
var z=a["list"].length;
var zy= Math.ceil(z/t);
window.onload=function (){
fanye(0);
}
function fanye(f)
{
if(y==1 && f==-1)
{
alert('已经是第一页了');
f=0;
}
if(y==zy && f==1)
{
alert('已经是最后一页了');
f=0;
}
var otbod=document.getElementById('table').tBodies[0];
var s=otbod.rows.length;
for(i=0;i<s;i++)
{
otbod.removeChild(otbod.rows[0]);
}
y+=f;
var q=(y-1)*2;//页数-1 乘以每页现实多少条 结果为 本页从第几条开始
for(var i=1;i<3;i++)
{
var otr=document.createElement('tr');
var otd1=document.createElement('td');
var otd2=document.createElement('td');
var otd3=document.createElement('td');
var otd4=document.createElement('td');
otd1.innerHTML=a["list"][q]['category1_id'];
otd2.innerHTML=a["list"][q]['category1_name'];
otd3.innerHTML=a["list"][q]['category1_intro'];
otd4.innerHTML=a["list"][q]['category1_images'];
otr.appendChild(otd1);
otr.appendChild(otd2);
otr.appendChild(otd3);
otr.appendChild(otd4);
otbod.appendChild(otr);
if(q==zy)
{
break;
}
q++;
}
}
</script>
</head>
<body>
<table border="1" id="table">
<thead>
<tr><td>category1_id</td><td>category1_name</td><td>category1_intro</td><td>category1_images</td></tr>
</thead>
<tbody>
</tbody>
</table>
<a href="javascript:fanye(1);">下一页</a>
<a href="javascript:fanye(-1);">上一页</a>
</body>
</html>
标签:json,页面分页
0
投稿
猜你喜欢
sqlserver 存储过程动态参数调用实现代码
2011-10-24 19:41:22
Python抽象类应用详情
2022-03-24 17:41:13
一文详解Python中logging模块的用法
2022-03-27 23:09:38
javascript数组去重方法总结(推荐)
2024-04-17 10:31:22
面向对象的CSS
2009-07-03 12:23:00
推荐几款MySQL相关工具
2024-01-23 10:42:12
caffe的python接口绘制loss和accuracy曲线
2021-06-15 23:54:21
js表单提交显示进度条
2007-09-18 13:10:00
GoLang channel关闭状态相关操作详解
2024-04-26 17:26:52
详解python使用canvas实现移动并绑定键盘
2022-08-18 01:02:52
vue简单的二维数组循环嵌套方式
2024-04-27 16:09:56
SQL Server 2000 占内存居高不下可能的原因及其解决方法
2010-04-25 10:39:00
如何将Python字符串转换为JSON的实现方法
2022-07-11 02:58:37
Python教程之成员和身份运算符的用法详解
2021-04-19 11:36:56
Python Pandas知识点之缺失值处理详解
2023-09-29 20:23:16
mysql正确安全清空在线慢查询日志slow log的流程分享
2024-01-24 12:25:48
asp测字符串长度及截取定长字符串汉字的处理
2007-10-12 13:14:00
进一步了解Python中的XML 工具
2022-06-25 21:49:17
python实现微信小程序用户登录、模板推送
2021-10-15 23:25:17
Vue3 defineExpose要在方法声明定义以后使用的教程
2024-05-21 10:30:03