<html>
<head>
<title>菜单切换内容示例</title>
</head>
<body>
<nav>
<ul>
<li><a href="#home">2024年</a>
|<a href="#about">2023年</a>
</li></ul>
</nav>
<section id="home">
<p><!--#include File="/logo/xr/gx/gl2024.htm"--></p>
</section>
<section id="about" style="display: none;">
<p><!--#include File="/logo/xr/gx/gl2023.htm"--></p>
<script>
//获取菜单列表
var menuList = document.querySelectorAll("nav ul li a");
//遍历菜单列表,绑定点击事件
for (var i = 0; i < menuList.length; i++) {
menuList[i].addEventListener("click", function(event) {
//获取当前被点击的菜单链接的href属性
var href = this.getAttribute("href");
//获取对应的内容节点
var content = document.querySelector(href);
//隐藏所有内容节点
var allContent = document.querySelectorAll("section");
for (var j = 0; j < allContent.length; j++) {
allContent[j].style.display = "none";
}
//显示对应的内容节点
content.style.display = "block";
//阻止默认跳转行为
event.preventDefault();
});
</script>
</body>
</html>