标签:function nojejs myDiv data getElementById var document 出子 取值
1、主窗口:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="javascripts/jquery-3.2.1.min.js"></script>
</head>
<body>
<input type="text" id="message" disabled="disabled">
<br>
<input type="button" id="bt1" value="弹出框">
</a>
<div id="myDiv" οnclick="cancle(this);"
style="position: absolute; width: 100%; height: 100%; z-index: 998">
<div id="popupDiv"
style="position: absolute; width: 60%; height: 60%; position: absolute; left: 50%; top: 50%; margin-left: -40%; margin-top: -20%;">
<iframe id="myFrame" frameborder="0" src="./show"
style="position: absolute; width: 100%; height: 100%; border-radius: 3px;"></iframe>
</div>
</div>
</body>
<script type="text/javascript">
var myDiv = document.getElementById("myDiv");
function myfun() {
// 隐藏myDiv
myDiv.style.display = "none";
}
$(document).ready(function(){
$("#bt1").click(function(){
$("#myDiv").toggle();
})
})
function get(data) {
var message = document.getElementById("message");
message.value = data;
myDiv.style.display = "none";
}
window.onload = myfun;
</script>
</html>
2 子窗口
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="javascripts/jquery-3.2.1.min.js"></script>
</head>
<body>
<div id="allDiv">
<input type="text" id="data" value="默认值"> <input type="button"
id="send" value="传值给父窗口">
<h1>弹出框</h1>
<h1>弹出框</h1>
</div>
</body>
<script type="text/javascript">
function load() {
// 设置滚动条
var allDiv = document.getElementById("allDiv");
allDiv.style.overflow = "auto";
}
$(document).ready(function(){
$("#send").click(function(){
var data = document.getElementById("data").value;
alert(data);
window.parent.get(data);
})
});
window.onload = load;
</script>
</html>
经vsc调试,测试能达到预期目标,取值能成功返回。
标签:function,
nojejs,
myDiv,
data,
getElementById,
var,
document,
出子,
取值
From: https://www.cnblogs.com/ybHsir/p/16712351.html