이 기사에서는 JavaScript 브라우저 Windows간에 데이터를 전달하는 방법에 대해 설명합니다. 참조를 위해 공유하십시오. 특정 분석은 다음과 같습니다.
요약:
프로젝트 개발에서 우리는 종종 팝업 창을 겪습니다. 일부는 DIV를 사용하여 팝업 효과를 시뮬레이션하고 일부는 IFRAME를 사용하며 일부는 Windows를 사용하여 창과 함께 제공되는 열린 기능을 통해 새 창을 열었습니다. 오늘은 Window.open () 함수를 통한 마지막 유형의 데이터 상호 작용을 공유하겠습니다. 먼저 렌더링을보십시오.
원칙:
상위 창에 의해 자식 창으로 전달 된 데이터는 URL의 매개 변수를 통해 전달되며, 부모 창으로 자식 창으로 전달 된 데이터는 상위 창의 전역 기능을 통해 전달됩니다.
암호:
index.html은 다음과 같습니다.
다음과 같이 코드를 복사하십시오. <! doctype html>
<html lang = "en">
<헤드>
<meta charset = "utf-8">
<title> 문서 </title>
</head>
<body>
<div id = "content"> </div>
<버튼 id = "테스트"> 버튼 </button>
<cript>
var test = document.getElementById ( 'test');
test.onclick = function () {
st
};
window.getContent = function (tx) {
document.getElementById ( 'content'). innerText = tx;
}
</스크립트>
</body>
</html>
window.html은 다음과 같습니다.
다음과 같이 코드를 복사하십시오. <! doctype html>
<html lang = "en">
<헤드>
<meta charset = "utf-8">
<title> 문서 </title>
</head>
<body>
<div id = "content"> </div>
<select name = ""id = "city">
<옵션 값 = "상하이"> 상하이 </옵션>
<옵션 값 = "hangzhou"> hangzhou </옵션>
</선택>
<cript>
var params = location.href.substring (location.href.lastindexof ( '?')+1) .split ( '&');
document.getElementById ( 'content'). innerText = params;
var city = document.getElementById ( 'city');
city.onchange = function () {
Window.opener.getContent (City.Value);
}
</스크립트>
</body>
</html>
참고 : 여기서 실행할 서비스 환경이 있습니다
이 기사가 모든 사람의 JavaScript 프로그래밍에 도움이되기를 바랍니다.