Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在另一个html文件(如php include()函数)中导入html_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何在另一个html文件(如php include()函数)中导入html

Javascript 如何在另一个html文件(如php include()函数)中导入html,javascript,jquery,html,Javascript,Jquery,Html,我想在我的所有页面中包括页眉和页脚。我可以使用include()函数在php中包含。但我只有.html文件。那么是否有任何html标记包含另一个html文件。使用html导入 <head> <link rel="import" href="/path/to/file/file.html"> </head> 使用jquery,您可以执行ajax请求: $('footer').load('/yourPage.html', function () {

我想在我的所有页面中包括页眉和页脚。我可以使用include()函数在php中包含。但我只有.html文件。那么是否有任何html标记包含另一个html文件。

使用html导入

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

使用jquery,您可以执行ajax请求:

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

如果你的服务器支持,你可以使用我试过的。但它尚未在浏览器中渲染。但是在代码中添加了外部文件标记view@sasikumar您仍然需要将内容插入dom中的某个位置。他的代码只将其存储到内容变量中。如果您有一个dom节点,请使用这个,如果您有文本,请使用.innerHTML。
 $('footer').load('/yourPage.html', function () {
    //if you need to do something after
 });