使页眉和页脚文件包含在多个html页面中 [英] Make header and footer files to be included in multiple html pages
本文介绍了使页眉和页脚文件包含在多个html页面中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建包含在几个html页面上的公共页眉和页脚页面。
I want to create common header and footer pages that are included on several html pages.
我想使用javascript。有没有办法只使用html和JavaScript?
I'd like to use javascript. Is there a way to do this using only html and JavaScript?
我想在另一个HTML页面加载页眉和页脚页面。
I want to load a header and footer page within another html page.
推荐答案
您可以使用 jquery 完成此操作。
You can accomplish this with jquery.
将此代码放在 index.html
<html>
<head>
<title></title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(function(){
$("#header").load("header.html");
$("#footer").load("footer.html");
});
</script>
</head>
<body>
<div id="header"></div>
<!--Remaining section-->
<div id="footer"></div>
</body>
</html>
并将此代码放在 header.html
index.html
<a href="http://www.google.com">click here for google</a>
现在,当您访问 index.html
,您应该可以点击链接标签。
Now, when you visit index.html
, you should be able to click the link tags.
这篇关于使页眉和页脚文件包含在多个html页面中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文