Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery点击赢得';不能使用新的无限滚动元素_Jquery_Onclick_Infinite Scroll - Fatal编程技术网

jQuery点击赢得';不能使用新的无限滚动元素

jQuery点击赢得';不能使用新的无限滚动元素,jquery,onclick,infinite-scroll,Jquery,Onclick,Infinite Scroll,在我的页面上,我有一个项目列表,您可以单击“查看更多”按钮,该按钮显示有关此主题的更多信息。这个单击函数在另一个页面的jQuery中。我在这个页面上实现了一个无限滚动条,但是现在“查看更多”按钮对新元素不起作用,只对第一个元素起作用 仅供参考:我没有编写这个应用程序,我的任务只是添加无限卷轴 我在网上搜索过这个问题,我读过几次,这可能是因为新元素没有初始化或其他原因。但我从未找到解决这个问题的方法 以下是无限滚动条的代码: var-reachedEnd=false $(window).scrol

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

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

我在网上搜索过这个问题,我读过几次,这可能是因为新元素没有初始化或其他原因。但我从未找到解决这个问题的方法

以下是无限滚动条的代码:

var-reachedEnd=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;
            }
        });
    }
}
“查看更多”单击功能的代码:

$('.click-job-viewmore').click(function(e) {

    var abtn = $(this).parents('.sresult-row').find('.job-btn-submit');
    var abtn_submitted = $(this).parents('.sresult-row').find('.job-btn-submitted');
    var requestinterviewbtn = $(this).parents('.sresult-row').find('.jobseeker_request_interview');

    var oDom = $(this).parents('.sresult-row').find('.sresult-par2');
    var aMark = $(this).parents('.sresult-row').find('.job-mark');
    var aViewMore = $(this).find('.job-viewmore');
    var aEdit = $(this).find('.job-edit');

    if (oDom.css('display') == 'none') {

        if (window.location.href.indexOf('search/searchJobseeker') > 0) {
            $.post(site_url + 'user/updateVisitNum',
                    {uid: aViewMore.attr('alt')},
            function(result) {
            });

        }

        aMark.addClass('job-mark2').removeClass('job-mark1');

        oDom.slideDown();

        abtn.css({display: 'block'}).show();
        abtn_submitted.css({display: 'block'}).show();

        requestinterviewbtn.css({display: 'block'}).show();

        aViewMore.html("View Less");
        aViewMore.css({
            'color': '#674092'
        });
    } else {
        oDom.slideUp();

        abtn.hide();
        abtn_submitted.hide();

        requestinterviewbtn.hide();

        aMark.addClass('job-mark1').removeClass('job-mark2');

        aViewMore.html("View More");
        aViewMore.css({
            'color': '#ea6e3b'
        });
    }

    e.stopPropagation();

    e.preventDefault();
});
试一试


因为您应该为动态创建的对象使用。它将帮助您为将来要创建的图元附加事件

这正是我需要的。我已经阅读了一些关于委托的内容,但我不知道是什么或如何进行的,因此感谢您的帮助。是否还有一种方法可以对jQuery.find(“elementname”);执行类似的操作;?因为此页面中也使用了某种类型的FXUITAB,它们不再工作。如果它们是静态元素,则可以使用find()方法。但是在动态元素的情况下,需要有委托人,他们在无限加载程序中也是动态的。但它们没有单击功能或其他功能,而是通过.find()进行搜索。那么我应该如何在这里使用这些代理呢?
Attach the click event to the document 

$(document).on('click','element' function(){}); 
Attach the click event to the document 

$(document).on('click','element' function(){});