이미 답변이 있으면 사과드립니다. 아무 것도 발견하지 못했습니다.속성으로 저장된 dom 요소에서 dom을 변경할 수 없습니다.
HTML 코드를 변경해야하는 블록이있는 약간의 JS 코드를 개발 중입니다. 다음 ID 태그로 초기화된다
- 사용자 정의 객체 : 그래서 나는 속성 2 종류의 주요 목적이있다.
내 첫 번째 버전이 작동했습니다. 일부 자바 스크립트 이벤트 및 메서드를 설정하면 내 블록 내용이 변경되었습니다.
물론 새로운 기능을 구현하기 위해 코드를 수정해야했지만 이제는 내 메소드가 html 코드를 반환하지만 내 변수에 .innerHTML이 더 이상 작동하지 않습니다.
내가 당신에게 몇 가지 코드를 보여주게하고
var AtelierScreen = function(ancre, dataJson){
if(!ancre.charAt) throw "Invalid string-dealer name type ('"+ancre+"') should be String";
if(ancre.length==0) throw "Invalid string-dealer name ('"+ancre+"') cannot be empty";
this.atelierContent;
this.operationMenu;
this.operationMenuContent;
this.operationRecap;
this.operationRecapContent;
this.create=function(obj,tagsuffix){
var tag = ancre+tagsuffix;
this.atelierContent.innerHTML += "<div id='"+tag+"'></div>";
var content = document.getElementById(tag);
if(!content) throw "Invalid html anchor using '"+tag+"' as an html id";
content.innerHTML=obj.getHtml();
return content;
}
try{
var dataObject = JSON.parse(dataJson);
this.atelierContent = document.getElementById(ancre);
if(!this.atelierContent) throw "Invalid html anchor using '"+ancre+"' as an html id";
// MENU
this.operationMenu = new OperationMenu(dataObject["dealer"],dataObject["operations"]);
this.operationMenuContent=this.create(this.operationMenu,"_menu");
this.operationMenuContent.innerHTML+="after init";
// RECAP
this.operationRecap = new OperationRecap();
this.operationRecapContent=this.create(this.operationRecap,"_recap");
this.operationMenuContent.innerHTML+="after recap init";
} catch(error){
throw "Error decoding json data :\n'"+error+"'\n\nJson =\n'"+dataJson+"'";
}
this.setSelectedModel=function(model){
this.operationMenuContent.innerHTML+="setSelectedModel";
var isTheSame = this.operationMenu.setSelectedModel(model);
if(!isTheSame) this.clearOperationItemFromRecap();
var temp = this.operationMenu.getHtml()
this.operationMenuContent.innerHTML=temp;
}
}
빠른 개요
- 내 모든 속성을하고이를 초기화하는 데 도움이되는 방법을 설명합니다.
- json 데이터를 확인하려면 try catch를 사용하십시오.
- 내가 프로그램 여기
와 상호 작용하는
- JSON 일이 무엇인가 초기화, 반환 첫 번째 콘텐츠 속성에 넣어지는 HTML 코드. 테스트로 dom에 텍스트를 다시 추가합니다. (작동합니다)
- 두 번째 블록이 만들어지고 두 번째 내용 속성에 html 코드가 반환됩니다. 첫 번째 컨텐츠 속성에 테스트로 텍스트를 다시 추가합니다. 이 시점에서 실패합니다.
- 내 방법이 어떤 방식 으로든 도움이되지 않습니다. 콘텐츠 속성이 응답하지 않는 것 같습니다.
콘텐츠 속성 값은 여전히 얻을 수 있습니다. atelierScreen.operationMenuContent.innerHTML; 그러나 DOM에 텍스트를 삽입 할 수 없습니다. atelierScreen.operationMenuContent.innerHTML = ""; 아무 작업도 수행하지 않습니다.
doc.getElement ...로 DOM을 쿼리해야합니까? 각 시간? DOM 요소가 속성으로 사용 된 이전 버전이 작동 중입니다 ...
누락되었으므로 매우 실망 스럽습니다.) 도와주세요. 감사합니다.