다음 코드를 사용하여 기타 문자열의 색상을 첫 번째 클릭에서 빨간색으로, 두 번째 클릭에서 연한색, 등 뒤로 두 가지 색상. 첫 번째 클릭에서 문자열이 빨간색으로 바뀌지 만 다음 클릭과 함께 빨간색으로 유지되며 그 이유를 알 수 없습니다.(배경색) 스위치가 작동하지 않습니다.
var string = document.getElementById("a-string");
if (string.backgroundColor !== "red") {
string.style.backgroundColor = "red";
} else {
string.style.backgroundColor = "lightblue";
}
캠 누구도 내가 예상 한대로 작동하지 않아야하는 이유를 알 수 있습니까?
변경'경우 ('에 string.backgroundColor! == ...이'(string.style.backgroundColor이! == ...' – destoryer
와우, 감사, 미안 내가 멍청한 놈이야 경우 그걸 발견 했어야 했어. – nmh