首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jQuery分页插件事件目标

jQuery分页插件事件目标
EN

Stack Overflow用户
提问于 2015-08-20 14:44:03
回答 1查看 1.3K关注 0票数 1

我正在使用jQuery分页插件,如下所示:

http://esimakin.github.io/twbs-pagination/

正如您在文档中所看到的,有一个关于“同步分页元素”的部分。我使用此功能将分页控件放置在内容的底部和顶部。

但是,当单击底部分页元素时,我希望实现某些特殊的滚动行为,这些行为不应该发生在单击顶部分页元素。

我想我可以使用event参数来调用onPageClick回调,但是,不管我单击顶部还是底部分页,事件总是将顶部分页作为其currentTarget列出。为什么即使当我单击底部分页控件时也会发生这种情况?这里有一个小提琴来演示:

http://jsfiddle.net/flyingL123/qerexw0L/1/

代码语言:javascript
复制
<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

代码语言:javascript
复制
$('.sync-pagination').twbsPagination({
    totalPages: 20,
    onPageClick: function (evt, page) {
        $('#sync-example-page-content').text('Page ' + page);
        console.log(evt);
    }
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-20 15:40:07

请在这里找到一个有用的小提琴:http://jsfiddle.net/2vL4addq/

您需要解决这种行为,因为类名将为您获得第一个条目(在您的例子中,您的ID=top,而不是底部)。要瞄准底部,您需要做一些您自己的绑定。

我创建了一个函数setupPaginators(),它是在文档就绪和页面按钮单击更改时使用的,以保持顶部和底部保持同步(不使用插件默认行为)。

代码语言:javascript
复制
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
    }));
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32121347

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档