-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinclude.js
More file actions
21 lines (19 loc) · 857 Bytes
/
Copy pathinclude.js
File metadata and controls
21 lines (19 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
document.addEventListener("DOMContentLoaded", () => {
const includes = document.querySelectorAll("[w3-include-html]");
includes.forEach(el => {
fetch(el.getAttribute("w3-include-html"))
.then(r => r.text())
.then(html => {
el.innerHTML = html;
el.removeAttribute("w3-include-html");
// 自动高亮当前页面
const currentPath = location.pathname; // 例如 /img/index.html
document.querySelectorAll(".header-btn").forEach(btn => {
const link = btn.parentElement.getAttribute("href") || "";
if (link === currentPath || (currentPath === "/" && link === "/index.html")) {
btn.classList.add("active");
}
});
});
});
});