我正在使用jQuery分页插件,如下所示:
http://esimakin.github.io/twbs-pagination/
正如您在文档中所看到的,有一个关于“同步分页元素”的部分。我使用此功能将分页控件放置在内容的底部和顶部。
但是,当单击底部分页元素时,我希望实现某些特殊的滚动行为,这些行为不应该发生在单击顶部分页元素。
我想我可以使用event参数来调用onPageClick回调,但是,不管我单击顶部还是底部分页,事件总是将顶部分页作为其currentTarget列出。为什么即使当我单击底部分页控件时也会发生这种情况?这里有一个小提琴来演示:
http://jsfiddle.net/flyingL123/qerexw0L/1/
<div class="text-center">
<ul class="sync-pagination pagination-sm pagination" id="top"></ul>
<div id="sync-example-page-content" class="well"></div>
<ul class="sync-pagination pagination-sm pagination" id="bottom"></ul>
</div>JS
$('.sync-pagination').twbsPagination({
totalPages: 20,
onPageClick: function (evt, page) {
$('#sync-example-page-content').text('Page ' + page);
console.log(evt);
}
});发布于 2015-08-20 15:40:07
请在这里找到一个有用的小提琴:http://jsfiddle.net/2vL4addq/
您需要解决这种行为,因为类名将为您获得第一个条目(在您的例子中,您的ID=top,而不是底部)。要瞄准底部,您需要做一些您自己的绑定。
我创建了一个函数setupPaginators(),它是在文档就绪和页面按钮单击更改时使用的,以保持顶部和底部保持同步(不使用插件默认行为)。
setupPaginators(1);
function setupPaginators(pageNumber){
// Default options for page.
var opts = {
totalPages: 20,
onPageClick: function (evt, page) {
$('#sync-example-page-content').text('Page ' + page);
console.log(evt);
if (($(this).attr("id") == "bottom")){
// Put your special bottom code here.
alert("bottom was clicked");
}
setupPaginators(page);
}
};
// Remove existing top.
$('#top').empty();
$('#top').removeData("twbs-pagination");
$('#top').unbind("page");
// Bind new top and override the startPage.
$('#top').twbsPagination($.extend(opts, {
startPage: pageNumber
}));
// Remove existing bottom.
$('#bottom').empty();
$('#bottom').removeData("twbs-pagination");
$('#bottom').unbind("page");
// Bind new bottom and override the startPage.
$('#bottom').twbsPagination($.extend(opts, {
startPage: pageNumber
}));
}https://stackoverflow.com/questions/32121347
复制相似问题