重写easyUI的alert方法,重写确认及X号方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_26346941/article/details/82801657

重写easyUI的alert方法

首先介绍一种用法  js方法向前兼容opt.close=opt.close||function(){};

就是默认值
function obj(opt) {
    opt=opt||{};
    opt.close=opt.close||function(){};
    this.close=opt.close;
}

var a = new obj();
a.close(); // 保证这样调用能正常执行,close有值。

var b = new obj({close: function() { alert('zswang路过'); }});
b.close(); // 也可以自己设置

默认参数的好处就是调用接口可以向前兼容。

这样使用在改写js插件原生方法时可以向原生方法添加内容;

重新实现easyUI的alert弹窗方法,点击X号和确认执行回调方法;

$.extend($.messager, {
    alert: function(title, msg, icon, fn, parent) {
        var isSubmit = false;
        //任务提交成功后提示信息去除图标
        if(parent == 'submit'){
            parent = undefined;
            isSubmit = true;
        }
        //给父窗口赋值(只有存在父窗口时才会自动赋值)
        if(!parent && frameElement && frameElement.api) {
            parent = frameElement.api;
        }
        //组织参数
        var params =  {
            title: title,
            id: 'customDCId',
            icon: 'confirm.gif',
            fixed: true,
            lock: true,
            width:280,
            //content: "<>"+msg+"<>",
            content: '<div style="padding-left: -2px;font-size: larger">' + msg + '</div>',
            resize: false,
            parent: parent || null,
            ok: function (here) {
                var api = this;
                var parentApi = api.config.parent;
                if(parentApi){
                    parentApi.zindex();
                }
                api.close();//存在缓存影响,先对提示框进行关闭处理
                if(fn){
                    fn.call(this, here);
                }
                return true;
            }
        };

        if(isSubmit){
            params.icon = '';
        }

        if(!parent){
            //存在父窗口自动使用父窗口的opener打开
            return $.dialog(params);
        }else{
            return parent.opener.$.dialog(params);
        }
    }

});

猜你喜欢

转载自blog.csdn.net/qq_26346941/article/details/82801657