Javascript 筛选新内容以仅显示特定的div
为了在页面中加载更多内容,我使用jQuery.get()函数检索外部页面链接 我可以检索所有页面,但是,当我试图过滤结果以仅获取“.container\u journal\u post”div时,我无法使其工作。 欢迎你的帮助 以下是我当前的HTML代码:Javascript 筛选新内容以仅显示特定的div,javascript,jquery,Javascript,Jquery,为了在页面中加载更多内容,我使用jQuery.get()函数检索外部页面链接 我可以检索所有页面,但是,当我试图过滤结果以仅获取“.container\u journal\u post”div时,我无法使其工作。 欢迎你的帮助 以下是我当前的HTML代码: <div id="related_projects" class="gridalicious"> <article><div class="container_journal_post"> post
<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>
职位1
职位2
以下是我的外部页面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>
34号职位
35后
下面是我的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 );
});
}
});
jQuery(文档).ready(函数($){
var pageNum=parseInt($(“#当前#页”)[0][“innerHTML”];
//获取页码
var max=parseInt($)[0][“innerHTML”];
//获取博客节的最大数目。
var nextLink=$(“#pagination.next”)[0][“href”];
//获取下一页帖子的链接。
//用户点击以加载更多帖子的按钮
$('#append')。单击(函数(){
makebox();
});
makebox=函数(){
var-box=新数组;
$.get(nextLink,函数(数据){
//控制台日志(数据);
//返回“nextLink”HTML DOM
//不能正确地切割它
//console.log($(数据));
//退回100件物品
//我想得到这样的东西:
$(数据).filter('article')。每个(
函数(键、值){
//值必须等于
//34号职位
框。推(值);
}
);
//在div的末尾加载新框
jQuery(“相关的项目”).gridalicious('append',box);
});
}
});
调用“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>
职位1
职位2
34号职位
35后
您可以使用jquery的加载功能:
$('#result').load('ajax/test.html#container')代码>
而#container
是获取内容的选择器
(请参阅)不幸的是,我已经准备好尝试这个,看看我做了什么:var result=$(“#相关的#u项目”).load(nextLink+”.container#u journal#u post”);var测试=结果[0][“子项”];在控制台内部,我得到了以下信息:[div#item00Higg.galcolumn,div#item10Higg.galcolumn,div#item20Higg.galcolumn,div#clear0Higg,item:function,namedItem:function]0:article.container\u journal\u post 1:article.container\u journal\u post 2:article.container\u post 3:article.container\u journal\u post 4:article.container\u post 5:article.container\u journal\u post 6:article.container\u journal\u post 7:article.container\u journal\u post 8:article.container\u post 9:article.container\u journal\u post 10:article.container\u journal\u post 11:article.container\u journal\u post length:12加载函数实际上将获取的内容直接填充到$(“#result”)中指定的元素。。。。。因此,您必须通过以下方式将其解析到结果数组中:var result=$(“#result”).children(“.container_journal_post”);但是,我不知道如何获得这些值,因为var test=result[0][“children”][0];return:使用该代码段获取所有'$('').html(数据).find('article').each(函数(键,值){box.push(值);});