本文介紹了layui彈窗父子窗口之間傳參數的方法,分享給大家,具體如下:
1、父頁面打開子頁面并向子頁面傳參數
function setChooseValues(ret){ var oView = document.getElementById("userName"); var oValue = document.getElementById("userIds"); var i = 0; if( ret != null){ oValue.value=""; oView.value=""; oView.title=""; for( x in ret){ 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=""; } } } function OpenFrame( oValue, oView) { var dialogArgumentsA = new Array(oValue.value , spitToString(oView)); var url = "${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();//關閉所有彈出層 //var parentWin = layero.find('iframe')[0]; var parentWin = layer.getChildFrame('body', index); alert(parentWin); parentWin.contentWindow.doOk(); //layer.close(index);//這塊是點擊確定關閉這個彈出層 }, */ area: ['750px', '450px'], content: url, success: function(layero, index){ var body = layer.getChildFrame('body', index); var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe頁的窗口對象,執行iframe頁的方法:iframeWin.method(); var ids = dialogArgumentsA[0].split(","); var names = dialogArgumentsA[1].split(","); for (var i = 0; i < ids.length; i++ ) { if ('' != ids[i]) { var option = $("<option>").val(ids[i]).text(names[i]); body.find('select').append(option); } } } }); }
2、子頁面向父頁面傳參數并關閉彈窗
function newBuildReturnValue(selectName){ var ret = new Array(); $("#"+selectName+" option").each(function(){ //遍歷所有option var value = $(this).val(); //獲取option值 var text = $(this).text(); if(text!=''){ var o = new Element(value, text, 0); ret.push(o); } }); return ret; } //點擊確定向子頁面傳參并關閉窗口 function doOk(){ var ret = newBuildReturnValue("select"); parent.setChooseValues(ret); var index = parent.layer.getFrameIndex(window.name); parent.layer.close(index); } //點擊取消關閉窗口 function doCancel(){ var index = parent.layer.getFrameIndex(window.name); parent.layer.close(index); }
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com