我有一些很棒的代码,可以很好地与 Wordpress 配合使用。它基本上向自定义循环添加了一个加载更多按钮,单击时会在下面添加下一批帖子。
我遇到的问题是这行代码取自以下代码段:error: function() { jQuery('button.load-more').attr('disabled', 'disabled').text('No More Posts') } // Disable the button and change its contents when there are no more posts
基本上,当没有更多帖子时,按钮不会按照指示被禁用。有人可以帮我解决吗?这是完整的JS:
var page = 1;
loadMore = function () {
page++ //Increments the page number in the request
$.ajax({
url: './page/' + page,
beforeSend: function () {
$('#wait').show().parent().find('button.load-more').hide();
},
complete: function () {
$('#wait').hide().parent().find('button.load-more').show();
},
success: function (data) {
var $data = $(data).find('article');
// Replace div#the-posts with the name of your post container
jQuery('#posts .inner').append($data);
},
error: function () {
jQuery('button.load-more').attr('disabled', 'disabled').text('No More Posts')
} // Disable the button and change its contents when there arew no more posts
}); // End Ajax
}; // End loadMore
jQuery('button.load-more').on('click', loadMore);