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(“网络错误”)
}
})