使用bootstrap-paginator.js 分頁(yè)來(lái)進(jìn)行ajax 異步分頁(yè)請(qǐng)求示例
使用bootstrap-paginator.js 分頁(yè)來(lái)進(jìn)行ajax 異步分頁(yè)請(qǐng)求
具體的做法如下 :
首先定義一個(gè)異步提交請(qǐng)求的ajax 函數(shù),其完整的函數(shù)如下:
var nid= $("#lbnid").val(); // 獲取當(dāng)前新聞編號(hào)
var cpage = 1; // 當(dāng)前頁(yè)面號(hào)
var tpage = 10; // 總頁(yè)面數(shù)
function getPaging() {
getComment(cpage); //獲取新聞評(píng)論
}
//點(diǎn)擊查看新聞評(píng)論
$("#one2").click(function () {
getPaging();
});
//獲取新聞評(píng)論評(píng)論
function getComment(page) {
$.ajax({
type: "get",
data: nid,
async: "false",
url: "/comment/GetComment?nid=" + nid+ "&page=" + page,
success: function (info) {
changeModel(info); // 更新局部頁(yè)面
var totalpage = $("#totalpage").val(); //當(dāng)前頁(yè)面號(hào)
var curtpage = $("#curtpage").val(); // 總頁(yè)面號(hào)
if (curtpage && totalpage) {
cpage = curtpage;
tpage = totalpage;
}
display(cpage, tpage); //顯示評(píng)論
},
error: function () {
alert("加載失?。≌?qǐng)稍后重試!");
}
});
}
/* obj: ajax 返回的html 數(shù)據(jù) */
// 更新局部頁(yè)面
function changeModel(obj) {
var comt = $(".Comments");
comt.replaceWith("<div class=Comments>" + obj + "</div>");
}
/* curreentpage: 當(dāng)前頁(yè)面號(hào); tpage: 總的頁(yè)面數(shù) */
//顯示新聞評(píng)論
function display(curtpage, tpage) {
var options = {
bootstrapMajorVersion: 3,//版本
currentPage: curtpage, //當(dāng)前頁(yè)數(shù)
numberOfPages: 10,//設(shè)置顯示的頁(yè)碼數(shù)
totalPages: tpage, //總頁(yè)數(shù)
itemTexts: function (type, page, current) {
switch (type) {
case "first":
return "首頁(yè)";
case "prev":
return "上一頁(yè)";
case "next":
return "下一頁(yè)";
case "last":
return "末頁(yè)";
case "page":
return page;
}
},
}
$("#page").bootstrapPaginator(options);
}
接下來(lái)就是修改原來(lái)的 bootstrap-paginator.js文件, 這也是最關(guān)鍵的一步
onPageClicked: function (event, originalEvent, type, page) {
//show the corresponding page and retrieve the newly built item related to the page clicked before for the event return
var currentTarget = $(event.currentTarget);
switch (type) {
case "first":
currentTarget.bootstrapPaginator("showFirst");
getComment(page); // 自定義的獲取新聞評(píng)論的方法,一寶要記得添加這個(gè)自定義的函數(shù)
break;
case "prev":
currentTarget.bootstrapPaginator("showPrevious");
getComment(page);
break;
case "next":
currentTarget.bootstrapPaginator("showNext");
getComment(page);
break;
case "last":
currentTarget.bootstrapPaginator("showLast");
getComment(page);
break;
case "page":
currentTarget.bootstrapPaginator("show", page);
getComment(page);
break;
}
},
接下來(lái)就OK了。運(yùn)行截圖如下:


以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Bootstrap Paginator+PageHelper實(shí)現(xiàn)分頁(yè)效果
- bootstrap paginator分頁(yè)插件的兩種使用方式實(shí)例詳解
- bootstrap paginator分頁(yè)前后臺(tái)用法示例
- 根據(jù)Bootstrap Paginator改寫的js分頁(yè)插件
- Bootstrap分頁(yè)插件之Bootstrap Paginator實(shí)例詳解
- Bootstrap Paginator分頁(yè)插件使用方法詳解
- Bootstrap Paginator分頁(yè)插件與ajax相結(jié)合實(shí)現(xiàn)動(dòng)態(tài)無(wú)刷新分頁(yè)效果
- bootstrap-paginator服務(wù)器端分頁(yè)使用方法詳解
相關(guān)文章
javascript 刪除數(shù)組中重復(fù)項(xiàng)(uniq)
巧妙去除數(shù)組中的重復(fù)項(xiàng)的方法參考,需要的朋友可以參考下。2010-01-01
JavaScript實(shí)現(xiàn)復(fù)制或剪切內(nèi)容到剪貼板功能的方法
這篇文章主要介紹了JavaScript實(shí)現(xiàn)復(fù)制或剪切內(nèi)容到剪貼板功能的方法,我們平時(shí)看到的網(wǎng)頁(yè)上很多一鍵復(fù)制功能就是如此實(shí)現(xiàn),需要的朋友可以參考下2016-05-05
JavaScript中window.showModalDialog()用法詳解
這篇文章主要介紹了JavaScript中window.showModalDialog()用法詳解,需要的朋友可以參考下2014-12-12
html2canvas屬性和使用方法以及如何使用html2canvas將HTML內(nèi)容寫入Canvas生成圖片
為大家介紹一款JS截圖插件html2canvas.js, 它可以通過(guò)純JS對(duì)瀏覽器端經(jīng)行截屏,下面就為大家介紹一下html2canvas.js屬性和具體使用方法,并為大家提供了一個(gè)實(shí)例2020-01-01
JavaScript ES2019中的8個(gè)新特性詳解
這篇文章主要介紹了JavaScript ES2019中的8個(gè)新特性詳解,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-02-02
JavaScript Cookie顯示用戶上次訪問(wèn)的時(shí)間和次數(shù)
用cookies記錄用戶的訪問(wèn)時(shí)間與次數(shù),然后再次訪問(wèn)時(shí),在讀取。2009-12-12

