세 개의 상자가 있습니다. 상자를 클릭하면 해당 항목 div
이 표시되고 배경색이 빨간색이됩니다. 하지만 같은 상자를 두 번 클릭 div
하면 아이콘이 사라지지만 배경은 그대로 유지됩니다 (흰색이됩니다). 도와주세요, 제발.
작은 것 :
이 부분을 함수 끝에 넣으십시오 show_hide_f()
.
if (obj.style.display != "block") {
obj.style.display = "block";
} else {
obj.style.display = "none";
document.getElementById("webLI").style.background = "white";
document.getElementById("personalLI").style.background = "white";
document.getElementById("postLI").style.background = "white";
}
전체 JS 업데이트 :
function show_hide_f(id) {
var obj = document.getElementById(id);
var objPortal = document.getElementById("web");
var objPersonal = document.getElementById("personal");
var objPost = document.getElementById("post");
if (obj == objPortal) {
document.getElementById("webLI").style.background = "red";
document.getElementById("personalLI").style.background = "white";
document.getElementById("postLI").style.background = "white";
objPersonal.style.display = "none";
objPost.style.display = "none";
} else if (obj == objPersonal) {
document.getElementById("webLI").style.background = "white";
document.getElementById("personalLI").style.background = "red";
document.getElementById("postLI").style.background = "white";
objPortal.style.display = "none";
objPost.style.display = "none";
} else if (obj == objPost) {
document.getElementById("postLI").style.background = "red";
document.getElementById("personalLI").style.background = "white";
document.getElementById("webLI").style.background = "white";
objPersonal.style.display = "none";
objPortal.style.display = "none";
}
if (obj.style.display != "block") {
obj.style.display = "block";
} else {
obj.style.display = "none";
document.getElementById("webLI").style.background = "white";
document.getElementById("personalLI").style.background = "white";
document.getElementById("postLI").style.background = "white";
}
}
여기에서도 변경 사항을 참조하십시오 : http://jsfiddle.net/zh6hje9w/2/
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다