小编Lew*_*wis的帖子

jQuery click不适用于新的无限滚动元素

在我的页面上,我有一个包含项目的列表,您可以单击"查看更多"按钮,该按钮显示有关此主题的更多信息.此单击函数位于另一页的jQuery中.我在这个页面上实现了一个无限卷轴,但是现在按钮"查看更多"对新元素不起作用,只对第一个元素起作用.

仅供参考:我没有编写这个应用程序,我的任务只是添加无限滚动.

我在网上搜索过这个问题,我读过几次这可能是因为新元素没有初始化或者其他东西.但我从未发现如何解决这个问题.

这是无限卷轴的代码:

var reachEnd = false;

$(window).scroll(function() {
    if ($(window).scrollTop() == $(document).height() - $(window).height()) {
            lastPostFunc();
    }
});

function lastPostFunc() {

    var trs = $('.sresult-row'); /*get the number of trs*/
    var count = trs.length; /*this will work as the offset*/

    /*Restricting the request if the end is reached.*/
    if (reachedEnd == false) {
        $.ajax({
            url: "http://localhost:8080/jingjobs/index.php/search/ajax_searchJob/" + count,
            async: false,
            dataType: "html",
            success: function(data) {
                if (data != "End")
                    $('.result-bd').append(data);
                else
                    reachedEnd = true;
            }
        });
    }
} …
Run Code Online (Sandbox Code Playgroud)

jquery onclick infinite-scroll

0
推荐指数
1
解决办法
1313
查看次数

标签 统计

infinite-scroll ×1

jquery ×1

onclick ×1