使页眉和页脚文件包含在多个 html 页面中 [英] Make header and footer files to be included in multiple html pages

查看:25
本文介绍了使页眉和页脚文件包含在多个 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.

将此代码放在index.html

<html>
<head>
<title></title>
<script
    src="https://code.jquery.com/jquery-3.3.1.js"
    integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
    crossorigin="anonymous">
</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.htmlfooter.html 中,与 index.html

and put this code in header.html and footer.html, at the same location as 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屋!

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