引入JS 链接:https://pan.baidu.com/s/1NQtcBoJ9iXIHeXiEFjDAWg 密码:454a
HTML :命名个容器用来装分页
<ul id="pagination-demo" class="pagination m--margin-10"></ul>
JS:
// 初始化分页
var $pagination = $('#pagination-demo');
var defaultOpts = {
startPage: 1,
totalPages: 1,
first: '« 首页',
prev: '‹ 上一页',
next: '下一页 ›',
last: '末页 »'
};
$pagination.twbsPagination(defaultOpts);
var pageIndex = 1; // 第几页
function find(){
$.ajax({
})
//重新加载分页控件
var totalPages = res.data.total ? Math.ceil(Number(res.data.total) / res.data.pageSize) : 0; //总共多少页
var currentPage = $pagination.twbsPagination('getCurrentPage'); //第几页
console.log(totalPages, currentPage);
$pagination.twbsPagination('destroy');
$pagination.twbsPagination($.extend({}, defaultOpts, {
startPage: currentPage,
totalPages: totalPages
})).on('page', function (evt, page) {
console.log("点击回调事件:" + page);
pageIndex = page; //第几页
find()
});
}