<script>
// 获取所有导航a标签
const links = document.querySelectorAll('nav a');
// 获取当前URL路径信息
const path = location.pathname + location.search;
links.forEach(function(item) {
//console.log(path);
//console.log(item.getAttribute('href'));
// 检索href是否存在匹配项并添加高亮class
if (path.indexOf(item.getAttribute('href')) !== -1) {
item.classList.add('active');
}
})
</script>