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

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

问题描述

我有2个HTML文件,假设 a.html b.html 。在 a.html 中我想包含 b.html

在JSF中,我可以这样做:

 < ui:include src =b.xhtml/> ; 

这意味着在 a.xhtml 文件中,我可以包含 b.xhtml



我们如何在 *中做到这一点。在我看来,最好的解决方案使用jQuery:

$ b file?

解决方案


$ b

a.html

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

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

b.html

 < p>这是我的包含文件< / p> 

这个方法对我的问题是一个简单而干净的解决方案。



jQuery .load()文档是这里


I have 2 HTML files, suppose a.html and b.html. In a.html I want to include b.html.

In JSF I can do it like that:

<ui:include src="b.xhtml" />

It means that inside a.xhtml file, I can include b.xhtml.

How can we do it in *.html file?

解决方案

In my opinion the best solution uses jQuery:

a.html:

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

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

b.html:

<p>This is my include file</p>

This method is a simple and clean solution to my problem.

The jQuery .load() documentation is here.

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

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