Include another HTML file in a HTML file

题意:在 HTML 文件中包含另一个 HTML 文件

问题背景:

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

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

In JSF I can do it like that:

在 JSF 中,我可以这样做:

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

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

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

How can we do it in *.html file?

我们如何在 *.html 文件中做到这一点?

问题解决:

In my opinion the best solution uses jQuery:

在我看来,最好的解决方案是使用 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.

jQuery .load() 的文档在这里。

猜你喜欢

转载自blog.csdn.net/suiusoar/article/details/143483200