简体   繁体   English

如何在另一个类似php include()函数的HTML文件中导入HTML

[英]How import html in another html file like php include() function

I want to include header and footer in all of my pages. 我想在所有页面中包含页眉和页脚。 I can include in php by using include() function. 我可以使用include()函数包含在php中。 But I have only .html file. 但是我只有.html文件。 So is there any html markup to include another html file. 因此,是否有任何html标记包含另一个html文件。

With jquery you can do an ajax request: 使用jquery,您可以执行一个ajax请求:

 $('footer').load('/yourPage.html', function () {
    //if you need to do something after
 });

Using HTML Imports 使用HTML导入

<head>
  <link rel="import" href="/path/to/file/file.html">
</head>

And use it with: 并用于:

var content = document.querySelector('link[rel="import"]').import;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM