每次我想要使用它时,是否必须重写一个html标头? [英] Do I have to rewrite an html header everytime I want to use it?
问题描述
我目前正在尝试使用node.js开发一个网站。由于不熟悉html和node.js,我遇到了一些麻烦。在node.js或html中是否有任何机制,我不必重新创建头文件&每个网页的页脚(例如:每次复制粘贴HTML代码)?
I'm currently trying to develop a site using node.js. I'm having some trouble due to my unfamiliarity with html and node.js. Is there any mechanism in either node.js or html where I don't have to recreate a header & footer for every single web page (eg: copy paste the html code each time)?
推荐答案
不知道这会回答你的问题,但它是在HTML页面中添加页眉和页脚而不重复代码的一种方法。 / p>
Not sure this will answer you question but it's one way to add header and footer in HTML pages without repeating the code.
<script>
$(function(){
$("#header").load("header.html");
$("#footer").load("footer.html");
});
</script>
并在您的主index.html文件中将为
and in your main index.html file will be
<div id="header"></div>
<div id="content">
Main Content
</div>
<div id="footer"></div>
因此,完整的index.html将如下所示:
So the complete index.html will be look like this
<html>
<head>
<title></title>
<script src="//code.jquery.com/jquery.min.js"></script>
<script>
$(function(){
$("#header").load("header.html");
$("#footer").load("footer.html");
});
</script>
</head>
<body>
<div id="header"></div>
<div id="content">
Main Content
</div>
<div id="footer"></div>
</body>
</html>
这篇关于每次我想要使用它时,是否必须重写一个html标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!