easyui dialog实现操作iframe内元素

//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

蛋疼的一晚上想到这种形式去实现,写完睡觉了!!!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

逍遥596607010

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值