Javascript/jQuery .load 将多个文件加载到 div 中

标签 javascript jquery

我使用此代码将文件的某些内容加载到 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/

相关文章:

java - 如何从 JavaScript 中访问存储在 session 中的数组变量?

javascript - 在剑道网格中对选定的行进行分组

php - 通过 jQuery/Ajax 调用 PHP 页面

jquery - 如何在隐藏元素溢出的jquery中获取IE7中的实际宽度

javascript - 复选框更改事件记录罚款或折扣jquery

jquery - 文本对齐居中而不是按钮中的文本居中

javascript - 模块构建失败 : Error: AotPlugin was detected but it was an instance of the wrong class

javascript - 防止 node_modules 包更新的最佳方法

javascript - 从目录 (AD) 读取的 HTML 中删除电子邮件签名中的行

javascript - jquery中如何结合打印和删除空输入?