Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

html - 在HTML文件中包含另一个HTML文件(Include another HTML file in a HTML file)

I have 2 HTML files, suppose a.html and b.html .

(我有2个HTML文件,假设a.htmlb.html 。)

In a.html I want to include b.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文件中执行此操作?)

  ask by lolo translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In my opinion the best solution uses jQuery:

(我认为最好的解决方案是使用jQuery:)

a.html :

(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 :

(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()文档在这里 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...