//js封装的dialog用iframe的方式实现
var js={dialog:'',iframe:{}};
js.showWindow=function (title,url,width,height,model,func) {
var uuid=js.uuid();
var iframe="iframe"+uuid;
var dialog="dialog"+uuid;
js.iframe=iframe;
js.dialog=dialog;
var content = '<iframe id="'+iframe+'" name="iframe'+uuid+'" src="' + url + '" width="100%" height="98%" frameborder="0" scrolling="no"></iframe>';
$("<div id='"+dialog+"'></div>").dialog({
title: title,
iconCls:'icon-window',
width: width,
height: height,
closed: true,
cache: false,
minimizable:true,
maximizable:true,
collapsible:true,
resizable:true,
content:content,
// url:url,
modal: model,
onMove:function(){
},
onMinimize:function(){
alert(123);
},
onClose:function(){
$("#"+dialog).dialog('destroy')
},
buttons:[{
iconCls:'icon-ok',
text:'确定',
handler:function () {
func()
//iframe.SubmitForm()
}
},{
iconCls:'icon-quxiao',
text:'取消',
handler:function(){
$("#"+dialog).dialog('destroy');
}
}]
});
js.iframe=window.frames[iframe];
};
js.uuid=function () {
var d = new Date().getTime();
var uuid = 'bxxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random()*16)%16 | 0;
d = Math.floor(d/16);
return (c=='x' ? r : (r&0x3|0x8)).toString(16);
});
return uuid;
};
//这是父页面要通过dialog调用子页面的 SubmitForm方法
function add() {
var data=g.treegrid('getSelected');
var pid;
if(!data){
pid=0;
}else{
pid=data.id;
}
js.showWindow('菜单添加','{:url("admin/auth/menu_add")}?pid='+pid,800,600,false,function () {
js.iframe.SubmitForm();
});
}
<form id="fm" method="post" action="{:url('auth/menu_save',['pid'=>$pid])}" novalidate style="margin:0;padding:20px 50px;float: left" >
<div style="margin-bottom:10px">
<input name="name" class="easyui-textbox" required="true" label="菜单名称:" style="width: 100%">
</div>
<div style="margin-bottom:10px">
<input name="app" class="easyui-textbox" required="true" label="应用名称:" style="width: 100%">
</div>
<div style="margin-bottom:10px">
<input name="controller" class="easyui-textbox" label="控制器:" style="width: 100%">
</div>
<div style="margin-bottom:10px">
<input name="action" class="easyui-textbox" label="方法:" style="width: 100%">
</div>
<div style="margin-bottom:10px">
<input name="js_action" class="easyui-textbox" label="js方法:" style="width: 100%">
</div>
<div style="margin-bottom:10px">
<select class="easyui-combobox" name="type" required="true" style="width:100%" label="是否为菜单">
<option value="">请选择</option>
<option value="1">只显示为菜单</option>
<option value="2">权限菜单</option>
<option value="3">按钮</option>
</select>
</div>
<div style="margin-bottom:10px">
<select class="easyui-combobox" name="is_show" required="true" style="width:100%" label="是否显示">
<option value="">请选择</option>
<option value="1">显示</option>
<option value="2">不显示</option>
</select>
</div>
<div style="margin-bottom:10px">
<input name="icon" class="easyui-textbox" label="图标:" style="width: 100%">
</div>
<div style="margin-bottom:10px">
<input name="sort" class="easyui-textbox" required="true" label="排序:" value="999" style="width: 100%">
</div>
<div style="margin-bottom:10px">
<input name="pid" class="easyui-textbox" required="true" label="上级菜单ID:" value="{$pid}" style="width: 100%">
</div>
</form>
<script>
//获取父节点
function SubmitForm(){
$("#fm").form('submit', {
url:"{:url('auth/menu_add')}",
onSubmit: function(){
var isValid = $(this).form('validate');
return isValid; // return false will stop the form submission
},
success: function(data){
var data=eval('(' + data + ')');
if(data.success){
layer.msg(data.message);
}
}
});
}
</script>
/**iframe加载的子页面***/
1.//根据iframe的id获取对象
2.var i1 = window.frames['iframeId'];
3.//var iframe =window.frames[0];也可以
4.//获取iframe中的元素值
5.var val=i1.document.getElementById("t1").value
//根据iframe的id获取对象
var i1 = window.frames['iframeId'];
//var iframe =window.frames[0];也可以
//获取iframe中的元素值
var val=i1.document.getElementById("t1").value
蛋疼的一晚上想到这种形式去实现,写完睡觉了!!!