有時候我們用easyui在后台框架中彈框的時候,總是顯示在框架頁面里面而不是整個系統框架的上面,看着有些不太樂意。
dialog = function (opts) { var query = parent.$, fnClose = opts.onClose; opts = query.extend({ title: 'My Dialog', width: 400, height: 220, closed: false, cache: false, modal: true, html: '', url: '', viewModel: query.noop }, opts); opts.onClose = function () { if (query.isFunction(fnClose)) fnClose(); query(this).dialog('destroy'); }; if (query.isFunction(opts.html)) opts.html = utils.functionComment(opts.html); else if (/^\#.*\-template$/.test(opts.html)) opts.html = $(opts.html).html(); var win = query('<div></div>').appendTo('body').html(opts.html); if (opts.url) query.ajax({ async: false, url: opts.url, success: function (d) { win.empty().html(d); } }); win.dialog(opts); query.parser.onComplete = function () { if ("undefined" === typeof ko) opts.viewModel(win); else ko.applyBindings(new opts.viewModel(win), win[0]); query.parser.onComplete = query.noop; }; query.parser.parse(win); return win; };
接下來我們來看看怎么調用這個通用的彈出方法:
var query = parent.$; var winAudit = query("#angelasp_div"); winAudit.dialog('open');
這樣看起來是不是是很簡單別忘了angelasp_div這個div或者標簽窗體代碼要在頂層框架頁面中定義:
如果你想讓框架頁面沒那么多繁瑣的html代碼,那么我們還可以這樣寫:
var html = '<div id="w_angelasp_div">' html += ' <div id="angelasp_div" class="easyui-dialog" title="標題" data-options="modal:true,closed:true,iconCls:\'icon-user-accept\'" style="width:400px;height:210px;" buttons="#w_audit_div_button">' html += ' <div class="container_16" style="width:90%;margin:5%;"> ' html += ' <div class="grid_13 val">窗體內容<div> ' html += ' </div> ' html += ' </div> ' html += ' <div id="w_audit_div_button" class="audit_button">' html += ' <a href="javascript:void(0)" data-bind="click:confirmClick" class="easyui-linkbutton" iconCls="icon-ok" >確定</a> ' html += ' <a href="javascript:void(0)" data-bind="click:cancelClick" class="easyui-linkbutton" iconCls="icon-cancel" >取消</a> ' html += ' </div> ' html += '</div>'; var winAudit= query(html).appendTo("body");
最后別忘了上面的那個open一下顯示。看看效果圖: