详解layui弹窗父子窗口之间传参数的方法
本文介绍了layui弹窗父子窗口之间传参数的方法,分享给大家,具体如下:
1、父页面打开子页面并向子页面传参数
functionsetChooseValues(ret){
varoView=document.getElementById("userName");
varoValue=document.getElementById("userIds");
vari=0;
if(ret!=null){
oValue.value="";
oView.value="";
oView.title="";
for(xinret){
i++;
oView.title=oView.title+ret[x].name+",";
oValue.value=oValue.value+ret[x].id+",";
oView.value=oView.value+ret[x].name+"\n";
}
if(i==0){
oView.value="";
}
}
}
functionOpenFrame(oValue,oView){
vardialogArgumentsA=newArray(oValue.value,spitToString(oView));
varurl="${rootPath}/page/system/roleallot/role_allot.jsp";
layer.open({
type:2,
skin:'layui-layer-lan',
title:'选择人员',
fix:false,
shadeClose:false,
maxmin:true,
id:'selectUser',
move:false,
closeBtn:2,
//以下代码为打开窗口添加按钮
/*btn:['确定','取消'],
btnAlign:'c',
yes:function(index,layero){
/*//layer.closeAll();//关闭所有弹出层
//varparentWin=layero.find('iframe')[0];
varparentWin=layer.getChildFrame('body',index);
alert(parentWin);
parentWin.contentWindow.doOk();
//layer.close(index);//这块是点击确定关闭这个弹出层
},*/
area:['750px','450px'],
content:url,
success:function(layero,index){
varbody=layer.getChildFrame('body',index);
variframeWin=window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method();
varids=dialogArgumentsA[0].split(",");
varnames=dialogArgumentsA[1].split(",");
for(vari=0;i").val(ids[i]).text(names[i]);
body.find('select').append(option);
}
}
}
});
}
2、子页面向父页面传参数并关闭弹窗
functionnewBuildReturnValue(selectName){
varret=newArray();
$("#"+selectName+"option").each(function(){
//遍历所有option
varvalue=$(this).val();//获取option值
vartext=$(this).text();
if(text!=''){
varo=newElement(value,text,0);
ret.push(o);
}
});
returnret;
}
//点击确定向子页面传参并关闭窗口
functiondoOk(){
varret=newBuildReturnValue("select");
parent.setChooseValues(ret);
varindex=parent.layer.getFrameIndex(window.name);
parent.layer.close(index);
}
//点击取消关闭窗口
functiondoCancel(){
varindex=parent.layer.getFrameIndex(window.name);
parent.layer.close(index);
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。