ajax局部重新整理分頁

來源:互聯網
上載者:User

標籤:io   ar   color   os   sp   java   for   資料   on   

//請求資料載入綁定頁面
function DindAjax(pageIndex) {
//擷取參數
var colors = $("#colorsVal").val();


$.ajax({
url: ‘/Ajax/muban/AjaxHandler.ashx‘,
type: ‘POST‘,
data: ‘ajaxType=pagelist&pageSize=40&pageIndex=‘ + pageIndex+ ‘&colors=‘ + colors,
dataType: ‘json‘,
async: false,
timeout: 6000,
error: function () { },
success: function (obj) {
result1 = eval(obj)[0];
result2 = eval(obj).splice(1, obj.length);

//有資料
if (result1.pagenum > 0) {
$(".content-nolist").hide();
$(".nolist-tj").hide();
$(".back-top").hide();
$(".fy-auto").html(pagesizelist(result1.pageIndex, result1.pagenum));
} else {
$(".nolist-tj").show();
$(".content-nolist").html(result1.result).show();
$(".fy-auto").html("");
$(".back-top").show();
}

}
});
if (result2 != null) {
firstLists = [];
newLists = [];
getJson(result2);
index = 0;
setBox(firstLists);

$(‘.content-lists‘).hide();
$(‘.loading‘).show();
imagesLoaded(document.querySelector(‘#masonry‘), function (instance) {

imgLoad($(‘#masonry‘));
$(‘.content-lists‘).show();
$(‘.loading‘).hide();
});

}


}

 

 

//列表綁定分頁
function pagesizelist(pageIndex, pagenum) {
var i = 0;
//當前頁碼
var pageIndex = parseInt(pageIndex);
//查詢的資料總記錄
var pagenum = parseInt(pagenum);

var pagehtml = ‘<a class="prev ‘ + (pageIndex == 1 ? ‘no-check‘ : ‘‘) + ‘" href="javascript:void(0);" ‘ + (pageIndex == 1 ? ‘‘ : ‘onclick="DindAjax(‘ + (pageIndex - 1) + ‘)"‘) + ‘><i class="iconfont">&#xe699;</i></a>‘;


//預設顯示分頁按鈕數量
var indexsize = 5;
//分頁中間值偏右
var indexleft = Math.ceil(indexsize / 2);

//分頁按鈕起始值
var smor = 0;
//分頁按鈕結束值
var big = 0;

//判斷分頁數量和總資料量
if (pagenum > indexsize) {
smor = pageIndex < indexleft ? 0 : ((pageIndex - indexleft) >= (pagenum - indexsize) ? (pagenum - indexsize) : (pageIndex - indexleft));
big = pageIndex < indexleft ? indexsize : (pageIndex == pagenum ? pageIndex : (pageIndex + ((pagenum - pageIndex) >= (indexsize - indexleft) ? (indexsize - indexleft) : (pagenum - pageIndex))));
} else {
smor = 0;
big = pagenum;
}


for (i = smor; i < big; i++) {
if (pageIndex == (i + 1)) {
pagehtml += " <span>" + pageIndex + "</span>";
} else {
pagehtml += "<a href=\"javascript:void(0)\" onclick=\"DindAjax(‘" + (i + 1) + "‘)\">" + (i + 1) + "</a>";
}
}

pagehtml += ‘<a class="prev ‘ + ((pageIndex + 1) > pagenum ? ‘no-check‘ : ‘‘) + ‘" href="javascript:void(0);" ‘ + ((pageIndex + 1) > pagenum ? ‘‘ : ‘onclick="DindAjax(‘ + (pageIndex + 1) + ‘)"‘) + ‘><i class="iconfont">&#xe698;</i></a>‘;


pagehtml += ‘ <div class="fl"><b>共‘ + pagenum + ‘頁</b> <b>到第</b><input onkeypress="if(event.keyCode==13){ pageValue(‘ + pagenum + ‘)};" onkeyup="javascript:value=value.replace(/[^0-9]/g,&quot;&quot;);" id="text_default" value="‘ + pageIndex + ‘" /><b>頁</b></div><button class="logobutton" onclick=\"pageValue(‘ + pagenum + ‘)">確定</button>‘;

return pagehtml;
}


function pageValue(pagenum) {
var num = $("#text_default").eq(0).val() >= pagenum ? pagenum : $("#text_default").eq(0).val();
DindAjax(num);
}

ajax局部重新整理分頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.