jQuery load multiple html files in one element

末鹿安然 提交于 2019-12-29 00:32:12

问题


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');

回答1:


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



回答2:


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);
});


来源:https://stackoverflow.com/questions/10605673/jquery-load-multiple-html-files-in-one-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!