在另一个html文件中包含html [英] Include html in another html file

查看:137
本文介绍了在另一个html文件中包含html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个htmlhead模板和一个导航模板,我想将其包含在我的网站的所有其他html文件中。
我发现这个帖子:



在HTML文件中包含另一个HTML文件



我的问题是...如果它是我想要的标题包括?



例如,我有以下文件结构:

  /var/www/includes/templates/header.html 
navigation.html

标题。 html可能如下所示:

 <!DOCTYPE html> 
< html lang =en>
< head>

< meta charset =utf-8>
< meta http-equiv =X-UA-Compatiblecontent =IE = edge>
< meta name =viewportcontent =width = device-width,initial-scale = 1>
< meta name =descriptioncontent =>
< meta name =authorcontent =>

< title>测试入口< / title>

< / head>

在这种情况下,我是否仍然可以在其他文章中创建一个div并通过jquery填充div?

解决方案

我认为这是使用jQuery将html内容/文件包含到另一个html文件中的最佳方式。

您可以简单地包含jQuery.js并使用 $(#DivContent)加载HTML文件。load(yourFile.html );



例如

  < HTML> 
< head>
< script src =jquery.js>< / script>
< script>
$(function(){
$(#DivContent)。load(another_file.html);
});
< / script>
< / head>

< body>
< div id =DivContent>< / div>
< / body>
< / html>

没有这样的标签可用于包含文件,但有一些第三方方法可用。

 <!DOCTYPE html> 
< html>
< script src =http://www.w3schools.com/lib/w3data.js>< / script>

< body>

< div w3-include-html =content.html>< / div>

< script>
w3IncludeHTML();
< / script>

< / body>
< / html>

有些人也使用

 <! - #include virtual =a.html - > 


I have a html "head" template and a navigation template that I want to include in all my other html files for my site. I found this post:

Include another HTML file in a HTML file

And my question is... what if it's the header that I want to include?

So for example, I have the following file structure:

 /var/www/includes/templates/header.html
                             navigation.html

header.html might look like this:

<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Test Portal</title>

 </head>

In a case like this, can I still follow the example in the other post where they create a div and populate the div via jquery?

解决方案

I think it would be best way to include an html content/file into another html file using jQuery.

You can simply include the jQuery.js and load the HTML file using $("#DivContent").load("yourFile.html");

For example

<html> 
  <head> 
    <script src="jquery.js"></script> 
    <script> 
    $(function(){
      $("#DivContent").load("another_file.html"); 
    });
    </script> 
  </head> 

  <body> 
     <div id="DivContent"></div>
  </body> 
</html>

There are no such a tags available to include the file but There are some third party methods available like this .

<!DOCTYPE html>
<html>
<script src="http://www.w3schools.com/lib/w3data.js"></script>

<body>

<div w3-include-html="content.html"></div> 

<script>
w3IncludeHTML();
</script>

</body>
</html>

Some people also used

<!--#include virtual="a.html" --> 

这篇关于在另一个html文件中包含html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆