参考https://www.cnblogs.com/chenluomenggongzi/p/6362705.html与pagination.js API
1 $.ajax({ 2 url: 'test.json', 3 type: 'GET', 4 dataType: 'json', 5 success: function (data) { 6 console.log(data.items.length); 7 var item = data.items, length = data.items.length, pageIndex; 8 //默认页面显示内容 9 showBox.html('姓名:' + item[0]['name'] + '\n' + '年龄:' + item[0]['age'] + '姓名:' + item[1]['name'] + '\n' + '年龄:' + item[1]['age']); 10 $("#M-box").pagination({ 11 totalData: length, 12 showData: 2, 13 jump: true, 14 coping: true, 15 homePage: '首页', 16 endPage: '末页', 17 prevContent: '上页', 18 nextContent: '下页', 19 callback: function (index) { 20 pageIndex = index.getCurrent() - 1; 21 showBox.html('姓名:' + item[pageIndex]['name'] + '\n' + '年龄:' + item[pageIndex]['age'] + '姓名:' + item[pageIndex]['name'] + '\n' + '年龄:' + item[pageIndex]['age']); 22 } 23 }) 24 }, 25 error: function () { 26 //错误处理 27 alert("操作超时,请刷新页面重试!"); 28 } 29 })