/** * 左侧菜单栏隐藏与显示 * @param span */ function toggle(span) {//span->this if (span.className === "open") { span.className = "closed"; span.nextElementSibling.className = "hide"; } else {//否则 var oldSpan = document.querySelector(".open"); if (oldSpan != null) { oldSpan.className = "closed"; oldSpan.nextElementSibling.className = "hide"; } span.className = "open"; span.nextElementSibling.className = "show"; } }
1 .middle .left li span { 2 cursor: pointer; 3 } 4 5 .middle .left .show { 6 display: block; 7 } 8 9 .middle .left .hide { 10 display: none; 11 } 12 13 .middle .left .open { 14 color: deepskyblue; 15 }