JavaScript implements JSON page paging instance code _javascript tips

Source: Internet
Author: User

In the afternoon, a friend asked the JSON data how to divide the page to do an dongdong out

The following direct code:

Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Untitled Document </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;//represents the number of pages
var t=2;//represents a few real data per page
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 (' Already the first page ');
f=0;
}
if (Y==zy && f==1)
{
Alert (' Already the last page ');
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;//number of pages-1 times per page Reality how many results for this page start with the first few
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>

<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);" > next Page </a>
<a href= "Javascript:fanye (-1);" > Prev </a>
</body>

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.