jQuery load multiple html files in one element

后端 未结 2 766
北荒
北荒 2020-12-11 06:22

How do i load multiple html files and putting them into a specified html element?

I tried with no changes:

$(\'#asd\').load(\'file.html,pippo.html\')         


        
相关标签:
2条回答
  • 2020-12-11 06:49

    you could get multiple items and add them to the element.

    jQuery.ajaxSetup({ async: false }); //if order matters
    $.get("file.htm", '', function (data) { $("#result").append(data); });
    $.get("pippo.htm", '', function (data) { $("#result").append(data); });
    jQuery.ajaxSetup({ async: true });  //if order matters
    
    0 讨论(0)
  • 2020-12-11 07:07

    Try this, using deferred objects.

    var defArr = [];
    defArr.push($.get('file.html'));
    defArr.push($.get('pippo.html'));
    $.when.apply($,defArr).done(function(response1,response2){
        $('.result').html(response1[2].responseText + response2[2].responseText);
    });
    
    0 讨论(0)
提交回复
热议问题