html分页请求代码,前端开发非异步请求做的分页

function qukong(a) {

if (a == “” || null) {

return “无”;

}

else {

return a;

}

};

$.ajax({

type: “get”,

url: “https://route.showapi.com/44-6?showapi_appid=32868&showapi_sign=37c9611696e648c9b5febf972ebffb99”,

dataType: “json”,

success: function (msg) {

var data_msg = msg.showapi_res_body.result;

//编造表数据

//表头

var head =

‘’ +

 彩票种类 ’ +

 地区 ’ +

 分类 ’ +

 描述 ’ +

 名称’ +

’;

var end = ‘

//表内容,后台返回的内容可以封装到这里,随时取用,但是如果数据量很大估计会相当耗

var pageData = [];

for (var key in data_msg) {

var data = ‘

’ +

’ + qukong(data_msg[key].series) + ‘’ +

’ + qukong(data_msg[key].area) + ‘’ +

’ + qukong(data_msg[key].issuer) + ‘’ +

’ + qukong(data_msg[key].notes) + ‘’ +

’ + qukong(data_msg[key].descr) + ‘’ +

’;

pageData.push(data);

}

$(function () {

var Count = pageData.length;//记录条数

alert(Count);

var PageSize = 10;//设置每页示数目

var PageCount = Math.ceil(Count / PageSize);//计算总页数

var currentPage = 1;//当前页,默认为1。

//造个简单的分页按钮

$(‘.total’).

$(‘.show_current’).

//显示默认页(第一页)

$(‘#table’).empty().append(head);

for (i = (currentPage – 1) * PageSize; i < 10; i++) {

$(‘#table’).append(pageData[i]);

}

$(‘#table’).append(end);

//显示选择页的内容

$(‘.next’).click(function () {

if (currentPage < PageCount) {

currentPage++;

$(‘.show_current’).

$(‘#table’).

$(‘#table’).append(head);

for (i = (currentPage – 1) * PageSize; i < PageSize * currentPage; i++) {

$(‘#table’).append(pageData[i]);

}

$(‘#table’).append(end);

}

});

$(‘.prev’).click(function () {

console.log(currentPage)

if (currentPage > 1) {

currentPage–;

$(‘.show_current’).html(currentPage);

$(‘#table’).html(”);

$(‘#table’).append(head);

for (i = (currentPage – 1) * PageSize; i < PageSize * currentPage; i++) {

$(‘#table’).append(pageData[i]);

}

$(‘#table’).append(end);

}

});

});

},

error: function () {

alert(“网络错误”)

}

})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值