在我的页面上,我有一个包含项目的列表,您可以单击“查看更多”按钮,该按钮会显示有关此主题的更多信息。这个点击函数是在另一个页面的 jQuery 中的。我在此页面上实现了无限滚动器,但现在“查看更多”按钮不适用于新元素,仅适用于第一个元素。
仅供参考:我没有编写此应用程序的代码,我的任务只是添加无限滚动。
我在网上搜索了有关此问题的信息,并且读过几次,这可能是因为新元素未初始化或其他原因。但我从来没有找到如何解决这个问题。
这是无限滚动器的代码:
var 到达结束 = 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();
});
try
$(document).on("click",".click-job-viewmore",function(e) {});
因为你应该使用代表们 https://api.jquery.com/on/对于动态创建的对象。它将帮助您附加事件以供将来创建的元素使用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)