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

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

问题描述

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

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

在 JSF 中,我可以这样做:

In JSF I can do it like that:

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

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

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

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

How can we do it in *.html file?

推荐答案

在我看来最好的解决方案是使用 jQuery:

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.

jQuery .load() 文档在这里.

The jQuery .load() documentation is here.

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

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