이 초보자의 질문에에 appendChild ("
")를 사용할 때 오류가 발생 ...내가 진짜 존재 참조
나는 내 웹 페이지에서 좌석 사진의 무리를 초기화하는 코드를 작성하려면
만들고 그들에게 설정 속성 하고 라인 (4 행, 모든 행이 9 석) 각 9 석을 변경하게는, 여기에 내가 무엇을 원하는 코드
function initSeats() {
var seatsDiv = document.getElementById("seats");
//Initialize the appearence of all seats
for (var i = 0; i < seats.length; i++) {
for (var j = 0; j < seats[i].length; j++) {
var currentSeatIndex = i * seats[i].length + j;
if (seats[i][j]) {
//if current seat is available(true), create a new IMG element and set some attributes;
} else {
//if current seat is unavailable(true), create a new IMG element and set some attributes;
}
}
seatsDiv.appendChild("<br>");//here is the problem
}
}
입니다 외부 루프 중 하나가 완료되면을 추가합니다. 마지막에,
그러나 나는 seatsDiv 그래서 결국 좌석의 한 행이 성공적으로 초기화 된
존재하지 않는 노드처럼 보이는 크롬에서 "NotFoundError"를 얻었다.appendChild가 해당 위치에 아무 것도 추가하지 않습니까? 아니면 다른 방법을 사용해야합니까? 노드가 아닌 문자열을 부여해야
seatsDiv.appendChild(document.createElement("br"));
에 appendChild : – Virus721
@ Virus721 감사합니다. 올바른 방법으로 생각하지 않는 것 같습니다. –