如何在一个html文件里包含或引用另一个html文件,本文章介绍二种方法。
第一种方法:jquery方法
jquery代码:
< >
$(function(){
var includes = $(\'[data-include]\');
jQuery.each(includes, function(){
var file = \'views/\' + $(this).data(\'include\') + \'.html\';
$(this).load(file);
});
});
</ >
html代码:
<div data-include=\"header\"></div>
<div data-include=\"footer\"></div>
以上代码实现了将views/header.html 和 views/footer.html包含加载到当前html文件中。
第二种方法:jquery load方法
a.html
<html>
<head>
< src=\"jquery.js\"></ >
< >
$(function(){
$(\"#includedContent\").load(\"b.html\");
});
</ >
</head>
<body>
<div id=\"includedContent\"></div>
</body>
</html>
b.html:
<p>This is my include file</p>
以上代码将b.html文件包含到a.html
继续阅读与本文标签相同的文章
上一篇 :
医疗AI如何助力于未来医院信息化建设?
-
第16问:Filecoin从DSN角度解读
2026-05-14栏目: 教程
-
C/C+从零基础到精通,究竟是如何快速完成的?其实只需要这6步!
2026-05-14栏目: 教程
-
谷歌再爆重大安全漏洞!华为却成最大赢家?网友:这谁还敢用!
2026-05-14栏目: 教程
-
Excel崩溃文件如何找回
2026-05-14栏目: 教程
-
又一外国巨头宣布退出中国,关闭120家店,网友:中国钱不好赚了!
2026-05-14栏目: 教程
