从外部源

时间:2015-09-21 05:16:42

标签: javascript jquery html ajax

给定脚本在点击时从外部源的特定div加载数据。现在尝试在加载图像和文本等内容时添加div类。我的意思是当内容加载新类时会自动添加<div class="images"> img</div><div class="summery"> text text text</div>

HTML:

<button class='btn'/>
<div id="load-here"></div> <!-- Load Here -->

</body>

脚本:

$(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('article.post.hentry');
                getNext();
            });
        } else if (page !== false) {
            getNext();
        }
    });
});

外部网站的HTML结构:每次点击都会收到脚本加载.date-outer。表示在点击时从外部站点/链接加载数据。

<body>
<div class="blog-posts hfeed"> 

<div class="date-outer">
Contecnt 1: img, text </div>

<div class="date-outer">
Contecnt 2: img, text </div>

<div class="date-outer">
Contecnt 3: img, text </div>

</div>
</body>

我的问题是加载数据时,想要使用给定的脚本向图像和文本添加自定义类。这是example site

0 个答案:

没有答案
相关问题