【发布时间】:2015-12-18 04:27:15
【问题描述】:
给定脚本在点击时从外部源的特定 div 加载数据。它从外部源的 div 中加载所有数据。但现在试图只加载我想要的特定东西。就像只加载图像,然后只加载标题、帖子标签、日期和 cmets,而不是文本摘要,以相同的顺序。
脚本:
$(function() {
var page = null;
var counter = 0;
function getNext() {
// Grab the next element from the array of date-outer divs and copy it to the .content div
if (counter >= page.length)
return;
var elm = $(page[counter]).clone();
elm.find('script').remove(); // Remove script tags in the div
elm.appendTo('#load-here');
counter++;
}
$('button.btn').click(function(e) {
if (page === null) {
page = false; // Prevents the request from being made twice
$.get('http://test-html-site.blogspot.com/search/label/', function(data) {
page = $(data).find('.date-outer');
getNext();
});
} else if (page !== false) {
getNext();
}
});
});
HTML:
<button class='btn'/>
<div id="load-here"></div> <!-- Load Here -->
</body>
外部网站的 HTML 结构:
给定脚本加载 .date-outer 每次点击。
<body>
<div class="blog-posts hfeed">
<div class="date-outer">
Contecnt 1: Title, img, comments, text </div>
<div class="date-outer">
Contecnt 2: Title, img, comments, text </div>
<div class="date-outer">
Contecnt 3: Title, img, comments, text </div>
</div>
</body>
示例外部站点link
单Content structure.
我的问题是如何以相同的顺序仅加载特定数据,例如图像,然后是标题、帖子标签、日期和 cmets,而不是文本摘要。
【问题讨论】:
标签: javascript jquery html ajax