国研兄弟遇到一个问题 问我我百度了下帮他解决了
下面是我参考的demo , 虽然不难不过以前没有遇到过这样的需求,就当多了解点姿势了。
<!--主页面的代码--><br><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="../../commonJS/jquery.js"></script>
<script>
</script>
</head>
<body>
<div style="width:140px; height:60px; position:relative;display:inline-block;background-color: red; margin-right:20px;display:inline-block;cursor: pointer;" id="addMatchSchedule"> </div>
</body>
</html>
<script>
$("#addMatchSchedule").click(function()
{alert("a");
window.open('child.html',"新增","width=500,height=480,screenX=400,screenY=100");
}
);
//子页面调用的函数
window.BBBB = function(){
alert(112);
}
//如果想传递参数可以在function(a){
// 这样传参
//}
</script>
<!--子页面--><br><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<script src="../../commonJS/jquery.js"></script>
<body>
<a class="btn btn-small btn-info" onclick="addSchduleItem();" title="确定" >确定</a>
</body>
</html>
<script>
//确定关闭页面
function addSchduleItem()
{
if (window.opener != null && !window.opener.closed) {
window.opener.BBBB();//调用主页面的函数
//let a = 1;
//window.opener.BBBB( a );调用主页面的函数 a是传递的参数。
}
window.close(true);
}
</script>
一句话概括思路:在父窗口中打开子窗口,在子窗口中调用父窗口的方法