我使用此代码将文件的某些内容加载到 div 中:
$('#mydiv').load('template1.html');
是否可以将多个加载到多个 div 中?
例如:
$('#mydiv', '#mydiv2').load('template1.html', 'template2.html');
如果是这样怎么办?
最佳答案
根据documentation , 不。你不能。
但是如果您想自动化,您可以使用关联对象吗?这只是一次尝试:
ajaxLoads = {
"#div1": "template1.html",
"#div2": "template2.html",
"#div3": "template3.html",
"#div4": "template4.html",
"#div5": "template5.html"
}
$.each(ajaxLoads, function (div, url) {
$(div).load(url);
});
关于Javascript/jQuery .load 将多个文件加载到 div 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34394362/