且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

HTML / CSS导航栏在多个页面上

更新时间:2023-02-11 13:36:50

这就是对我的帮助。我的导航栏位于body标签中。导航栏的整个代码位于 nav.html 文件中(没有任何html或body标签,只有导航栏的代码)。在目标页面中,它出现在标记中:

This is what helped me. My navigation bar is in the body tag. Entire code for navigation bar is in nav.html file (without any html or body tag, only the code for navigation bar). In the target page, this goes in the head tag:

<script src="https://code.jquery.com/jquery-1.10.2.js"></script>

然后在body标签中,一个容器由一个唯一的id和一个javascript块加载 nav.html 放入容器中,如下所示:

Then in the body tag, a container is made with an unique id and a javascript block to load the nav.html into the container, as follows:

<!--Navigation bar-->
<div id="nav-placeholder">

</div>

<script>
$(function(){
  $("#nav-placeholder").load("nav.html");
});
</script>
<!--end of Navigation bar-->