自动调整jQuery UI对话框在Internet Explorer中的大小

6

我该如何在Internet Explorer中自适应调整jQuery UI对话框的大小?

这段代码在Firefox中可以正常工作,但在Internet Explorer中不行。

$('#dialog2').dialog({
    autoResize: true,
    show: "clip",
    hide: "clip",
    height: 'auto',
    width: 'auto',
    autoOpen: false,
    modal: true,
    position: 'center',
    draggable: true,

    open: function (type, data) {
        $(this).parent().appendTo("form");

    },
    buttons: { "close": function () { $(this).dialog("close"); document.getElementById("<%=btnnew.ClientID%>").click(); } }
});

我的HTML元素是一个DIV。


你使用的是哪个版本的jQuery和jQuery UI? - Salman Paracha
2个回答

5

我使用以下“补丁”(适用于IE)成功地使用width: 'auto'调整大小jQuery UI对话框:

(function($) {
var fixDialogAutoWidth = $.noop;
if ( $.browser.msie ) {
    fixDialogAutoWidth = function(content) {
        var dialog = $(content).parent('.ui-dialog');
        var width = dialog.innerWidth();
        if ( width ) dialog.css('width', width);
    }
}

var _init = $.ui.dialog.prototype._init;
$.ui.dialog.prototype._init = function() {
    // IE magick: (width: 'auto' not working correctly) :
    // http://dev.jqueryui.com/ticket/4437
    if ( this.options.width == 'auto' ) {
        var open = this.options.open;
        this.options.open = function() {
            fixDialogAutoWidth(this);
            if ( open ) open.apply(this);
        }
    }
    // yet another bug options.hide: 'drop' does not work
    // in IE http://dev.jqueryui.com/ticket/5615
    if ( $.browser.msie && this.options.hide == 'drop' ) {
        this.options.hide = 'fold';
    }
    return _init.apply(this); // calls open() if autoOpen
};
})(jQuery);

在jquery-ui.js加载后,只需加载此代码即可...请注意,根据http://dev.jqueryui.com/ticket/4437的说明,我们不应该使用width: 'auto',但我离不开它... :)

我尝试了。我在 jQuery-ui.js 之后添加了此代码,但它还不起作用 :(. IE8 - Shahin
1
很抱歉它对您没有起作用 - 我会从记录并检查 fixDialogAutoWidthdialog.innerWidth() 的值开始... - kares

0
请先在以下行末添加一个,
buttons: { "close": function () { $(this).dialog("close"); document.getElementById("<%=btnnew.ClientID%>").click(); } }

IE 期望所有选项都通过 , 关闭。

让我们看看这是否奏效(最好询问此故障发生在哪个版本的 IE 上?)


根据我上面的建议,有任何结果吗? - Salman Paracha

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接