【问题标题】:Load specific data from external source从外部源加载特定数据
【发布时间】: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


    【解决方案1】:

    试试这个 sn-p 从外部源中选择特定内容

    $('#Destination-image1-Id').load('XXX.html #image1');
    

    参考:https://stackoverflow.com/a/4101874/2632619

    【讨论】:

    • 不是这样,需要点击功能,请看这里:test-html-site.blogspot.com 点击“点击这里”按钮时显示所有内容,但我想加载特定数据。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2013-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多