换成javascript代码$(this).children(".child-list").css({ display: "block" }).parent().siblings().children(".child-list").css({ display: "none" }); $(this).find("li").hover(function () { $(this).css({ color: "#ff6700" }) }, function () { $(this).css({ color: "#333" }) })
时间: 2024-04-02 14:34:23 浏览: 21
document.addEventListener("DOMContentLoaded", function() {
let parentList = document.querySelectorAll(".l-list > li");
for(let i = 0; i < parentList.length; i++) {
parentList[i].addEventListener("mouseenter", function() {
let childList = this.querySelector(".child-list");
childList.style.display = "block";
for(let j = 0; j < parentList.length; j++) {
if(j != i) {
parentList[j].querySelector(".child-list").style.display = "none";
}
}
});
let liList = parentList[i].querySelectorAll("li");
for(let j = 0; j < liList.length; j++) {
liList[j].addEventListener("mouseenter", function() {
this.style.color = "#ff6700";
});
liList[j].addEventListener("mouseleave", function() {
this.style.color = "#333";
});
}
}
});