interfaces/topic_4/example1/script.js

24 lines
783 B
JavaScript
Raw Normal View History

2023-04-07 05:21:44 +00:00
window.onload = function() {
let nav = document.getElementById("nav")
let items = nav.getElementsByClassName("menu-item");
for (let i = 0; i < items.length; i++) {
let item = items[i]
item.onclick = function () {
for (let j = 0; j < items.length; j++) {
if (i === j) {
continue
}
let oldItem = items[j]
oldItem.getElementsByClassName("submenu")[0].classList.remove('show')
}
let submenu = item.getElementsByClassName("submenu")[0];
if (submenu.classList.contains('show')) {
submenu.classList.remove('show')
} else {
submenu.classList.add('show')
}
}
}
}