숨겨진 입력 양식 필드에서 값을 검색해야하는 응용 프로그램이 있습니다. 그러나이 응용 프로그램에는 iFrame에있는 다른 페이지를 호출하는 기본 페이지가 있으며 다른 iFrame에서도 자체 페이지를 호출 할 수 있습니다.3 가지 방법으로 getElementById
default.asp -> screen.asp (iFrame에서) screen.asp -> 내가 기본에서 숨겨진 입력 양식 필드를 참조 할 때
document.getElementById('focusValue').value
window.frames[0].document.getElementById('focusValue').value
parent.frames[arrVal].document.getElementById('focusValue').value
(iframe에) screen.asp의 새로운 인스턴스 -> 화면 나는 표준 document.getElementById('focusValue').value;
를 사용할 수 있습니다. 다음 1 층 iFrame에있을 때 window.frames[0].document.getElementById('focusValue').value;
을 사용해야합니다. 그렇다면 iFrame의 2+ 레벨에있을 때 parent.frames[arrVal].document.getElementById('focusValue').value;
을 사용해야합니다.
if(document.getElementById('focusValue') == undefined){
window.frames[0].document.getElementById('focusValue').value = focusValue;
console.log('1');
}else if((parent.frames.length -1) == arrVal){
console.log('2');
if (arrVal > 0) {
parent.frames[arrVal].document.getElementById('focusValue').value = focusValue;
}
}else{
document.getElementById('focusValue').value = focusValue;
console.log('3');
}
나는 확실히이 작업을 수행 할 수 있지만 코멘트 새로운 가치를 작성하는 외부 내가 다른 프로그래머와 걱정 (또는 나에게 1 : 내가보고 시작 했어
일반적인 구조는 이것이다 이제부터이 코드를보고 내가하고있는 일에 궁금해한다.
제 질문은 제가 표준 형식으로하고자하는 것을 달성하는 방법이 있습니까? 이를 달성하는 더 좋은 방법이 있기를 정말로 바라고 있습니다.
그 이유는 발명 된 이유입니다. 당신이하고있는 것을 문서화하십시오. – Gerben