参考
https://www.cnblogs.com/BlingSun/p/7484237.html
父页面和子页面都是jBox弹窗
父页面调用子页面的方法:
//父页面的弹窗方法 (注意id:"doctorListIframe",)
function seletDoctorList(){
var url='${ctx}/zhong/doctor/list?isSelectTime='+"yesdd";
top.$.jBox("iframe:"+url, {
id:"doctorListIframe",
title: "咨询师信息",
width: 1150,
height: 500,
buttons :{'确定预约':1,'关闭':0},
showSpeed : 'fast',
submit:function(v,h,f){
if(v == 1){
// 获取子页面的值 listDoctorTime在子页面中是全局变量
var listDoctorTime=h.find("#jbox-iframe")[0].contentWindow.listDoctorTime;
//调用子页面的 tipFail()方法
h.find("#jbox-iframe")[0].contentWindow.tipFail();
//根据id获取子页面的值
var queueCode=
h.find("iframe")[0].contentWindow.document.getElementById("queueCode").value;
var queueCode=
h.find("iframe")[0].contentWindow.document.getElementById("queueCode").value;
//破编译器放一行都放不下格式乱七八糟的
}
}
}
子页面调用父页面的方法
方式1:
子页面parent.fu();//子调用父页面的方法
var saveAndNewWorksheet=parent.document.getElementById("saveAndNewWorksheet");
if(saveAndNewWorksheet!=undefined){//判断父元素是否存在
parent.fu();
}
父页面:
父页面中定义有 fu方法
function fu(){
//逻辑处理
}
方式2:
在jBox生成父页面的时候定义 id:"worksheetForm",
function openW(url,title){
console.log("open");
$.jBox("iframe:"+url, {
top:'5%',
id:"worksheetForm",
title: title,
width: window.top.innerWidth*0.8,
height: window.top.innerHeight*0.7,
persistent: true,
buttons :{},
showSpeed : 'fast',
closed: function () {
closeUpdate();
}
});
}
截图是父页面的iframe_ID
子页面触发调用父页面的方法:
<input type="button" onclick="closeWin()" value="得到父页面的方法" />
var listDoctorTime=new Array;//初始化预约集合
function closeWin(listDoctorTime,reserveTimeIds,appRoom) {
if(typeof parent.frames[name="jbox-iframe-worksheetForm"].removeRButton
=== "function"){
parent.frames[name="jbox-iframe-worksheetForm"].removeRButton();
}
parent.window.jBox.close();//关闭子页面的子页面
}