一、业务逻辑,共有四个界面,底层界面,以及三个业务界面,我统一概括为A,B,C界面
在A界面,点击按钮,弹出B界面
在B界面点击按钮,弹出C界面
进入C界面,点击选择后,将选择的数据,赋值 到B界面
并且关闭C界面
、
点击B界面的保存,即可关闭B界面,将数据显示在A界面
二、代码构思
由于B、C界面属于弹出框,无法通过窗体获取到值,但是可以获取A标签,使用弹出一个frame标签(B标签),再在B界面后弹出frame标签(C标签),
关闭的时候,C标签获取的是B标签的ID作为窗体,B标签获取的是A窗体,这样即可关闭,不过涉及到frame标签,每次点击都会弹出,例如此界面,我点击两次,弹出两次
这种情况下,就考虑关闭弹出窗体的同时,清除frame标签缓存,最终实现了
现在是A,B,C标签都有
现在关闭C标签
三、贴代码
底层界面代码
var activeOneDialog; function openOneDialog(dialogTitle, dialogHref, dialogWidth, dialogHeight) { var dialogProperties = { title: dialogTitle, dialogWidth, height: dialogHeight, modal: true } var dialogStr = '<div style="position:relative">'; dialogStr = dialogStr + '<iframe src="' + dialogHref + '" style=" 100%; height: 100%; overflow-x: hidden; overflow-y: auto" id="ifmDialog" frameborder="0" marginheight="0" marginwidth="0"></iframe>'; dialogStr = dialogStr + '</div>'; activeOneDialog = $(dialogStr).dialog(dialogProperties); } function closeOneDialog() { $(activeOneDialog).dialog('close'); var iframe = document.getElementById('ifmDialog'); //把iframe指向空白页面,这样可以释放大部分内存。 iframe.src = 'about:blank'; try { iframe.contentWindow.document.write(''); iframe.contentWindow.document.clear(); } catch (e) { } //把iframe从页面移除 iframe.parentNode.removeChild(iframe); } var actDialog; function openSecondDialog(dialogTitle, dialogHref, dialogWidth, dialogHeight) { var dialogProperties = { title: dialogTitle, dialogWidth, height: dialogHeight, modal: true } var dialogStr = '<div style="position:relative">'; dialogStr = dialogStr + '<iframe src="' + dialogHref + '" style=" 100%; height: 100%; overflow-x: hidden; overflow-y: auto" id="ifmDialogSecond" frameborder="0" marginheight="0" marginwidth="0"></iframe>'; dialogStr = dialogStr + '</div>'; actDialog = $(dialogStr).dialog(dialogProperties); } function closeSecondDialog() { $(actDialog).dialog('close'); var iframe = document.getElementById('ifmDialogSecond'); //把iframe指向空白页面,这样可以释放大部分内存。 iframe.src = 'about:blank'; try{ iframe.contentWindow.document.write(''); iframe.contentWindow.document.clear(); }catch(e){} //把iframe从页面移除 iframe.parentNode.removeChild(iframe); }
A界面代码
<!--前端JS--> function openAddDialog() { var ID = $("#dt_ID").val(); var title = 'B标签名字'; var href = '../Module_Sbjn/Sbjn_Qyb_ChildEdit.aspx?sbjnid=' + ID; //这里href必须是相对于底层界面的。 var width = 850; var height = 560; window.parent.openOneDialog(title, href, width, height); return false;//阻止按钮后台刷新 } function openEditDialog(ID) { var title = 'B标签名字'; var href = '../Module_Sbjn/Sbjn_Qyb_ChildEdit.aspx?childid=' + ID; //这里href必须是相对于底层界面的。 var width = 850; var height = 560; window.parent.openOneDialog(title, href, width, height); return false;//阻止按钮后台刷新 }
B界面代码
//前端js function openSelectDialog() { var applyYear = $("#ddl_year").val(); if (applyYear==null ||applyYear=="") { alert("请先选择申报年度!"); return false; } var title = 'C界面名称'; var href = '../Module_Sbjn/Sbjn_Qyb_ChildSelect.aspx?applyYear=' + applyYear; //这里href必须是相对于底层界面的。 var width = 700; var height = 300; window.parent.openSecondDialog(title, href, width, height); return false;//阻止按钮后台刷新 }
//后端代码 string ReturnString = string.Empty; ReturnString = "<script type='text/javascript'>"; ReturnString = ReturnString + "var thisWindowOpenedMe = parent.document.getElementById('ifmContentBody').contentWindow;"; //该窗体即为A界面 ReturnString = ReturnString + "thisWindowOpenedMe.ReloadInfo();"; ReturnString = ReturnString + "window.parent.closeOneDialog();</script>"; Response.Write(ReturnString);
C界面代码
//后端JS string ReturnString = string.Empty; ReturnString = "<script type='text/javascript'>"; ReturnString = ReturnString + "var thisWindowDialogdMe =parent.document.getElementById('ifmDialog').contentWindow;";//获取B标签页 ReturnString = ReturnString + "thisWindowDialogdMe.document.getElementById('dbt_QyID').value ='" + id + "';"; ReturnString = ReturnString + "thisWindowDialogdMe.document.getElementById('td_Qymc').value='" + Qymc + "';"; ReturnString = ReturnString + "thisWindowDialogdMe.document.getElementById('tb_Tyshxydm').value ='" + unionCreditCode + "';"; ReturnString = ReturnString + "thisWindowDialogdMe.document.getElementById('dbt_PersonQuantity').value ='" + PersonQuantity + "';"; ReturnString = ReturnString + "window.parent.closeSecondDialog();</script>"; Response.Write(ReturnString);