1

I make this script.

var arr = $('.siblings-list li').map(function() { return $(this).text() });
for (var i = 0; i < arr.length; i++) {
    $('.main').load(arr[i] + ' .section', function() {

    });
}

With this script. I get a array with url's and load the section of the url's in the main div. But i have a question with the load methode of jQuery. Now the script loads the section of the url's in the main div. And remove the html that's in the div. How can i change the script. That the current html in the main div not removed?

Thank you

4

2 回答 2

2
$.get(arr[i]).done(function (html) {
    $(".main").append($(html).find(".section"));
});

然而,这有点低效。理想情况下,您将能够通过单个请求返回您需要的所有 HTML(并且仅返回您需要的 HTML)。

于 2013-05-23T19:24:37.240 回答
0

当您使用 .load 时,它会覆盖选择器的完整内容,在这种情况下 .main 每次都会被覆盖。

尝试

$(".main").append($("<div>").load(arr[i] + ' .section', function() {

看看它是如何工作的?

于 2013-05-23T19:26:47.373 回答