为了在我的页面中加载更多内容,我正在使用 jQuery.get() 函数检索外部页面链接。
我可以检索所有页面,但是,当我尝试过滤结果以仅获取“.container_journal_post”div 时,我无法使其工作。欢迎您的帮助。
这是我当前的 HTML 代码:
<div id="related_projects" class="gridalicious">
<article><div class="container_journal_post"> post 1 </div></article>
<article><div class="container_journal_post"> post 2 </div></article>
</div>
这是我的外部页面 HTML 代码:
<div id="related_projects" class="gridalicious">
<article><div class="container_journal_post"> post 34 </div></article>
<article><div class="container_journal_post"> post 35 </div></article>
</div>
这是我的javascript函数:
jQuery(document).ready(function($) {
var pageNum = parseInt($("#current_page")[0]["innerHTML"]);
// Get the page number
var max = parseInt($("#max_num_pages")[0]["innerHTML"]);
// Get the maximum number of the blog section.
var nextLink = $("#pagination .next")[0]["href"];
// Get The link of the next page of posts.
// A button where the user is cliking to load more posts
$('#append').click(function(){
makeboxes();
});
makeboxes = function() {
var boxes = new Array;
$.get(nextLink, function(data) {
// console.log(data);
// Return the "nextLink" HTML DOM
// Can't cut it correctly
// console.log($(data));
// Return 100 items
// I would like to get something like this:
$(data).filter( 'article' ).each(
function( key, value ) {
// value has to be equal at
// <div class="container_journal_post"> post 34 </div>
boxes.push(value);
}
);
// load at the end of the div the new boxes
jQuery( "#related_projects" ).gridalicious( 'append', boxes );
});
}
});
调用“makebox”函数后想要的结果:
<div id="related_projects" class="gridalicious">
<article><div class="container_journal_post"> post 1 </div></article>
<article><div class="container_journal_post"> post 2 </div></article>
<article><div class="container_journal_post"> post 34 </div></article>
<article><div class="container_journal_post"> post 35 </div></article>
</div>