换成javascript代码$(function () {$(".l-list").children("li").hover(function () {$(this).css({ backgroundColor: "#ff6700" }).siblings().css({ backgroundColor: "transparent" });
时间: 2024-04-02 10:34:26 浏览: 96
用javascript实现li 列表数据隔行变换背景颜色
document.addEventListener("DOMContentLoaded", function() {
let lList = document.querySelector(".l-list");
let liList = lList.children;
for(let i = 0; i < liList.length; i++) {
liList[i].addEventListener("mouseenter", function() {
this.style.backgroundColor = "#ff6700";
for(let j = 0; j < liList.length; j++) {
if(j != i) {
liList[j].style.backgroundColor = "transparent";
}
}
});
liList[i].addEventListener("mouseleave", function() {
this.style.backgroundColor = "";
});
}
});
阅读全文