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

时间:2010-11-24 09:38:35

标签: jquery jquery-ui jquery-ui-dialog autosize

如何在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。

2 个答案:

答案 0 :(得分: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,我们不应该使用宽度:'自动',但我不能没有它......:)

答案 1 :(得分:0)

请先在下一行的末尾添加,

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

IE期望通过,

关闭所有选项

让我们看看是否有诀窍(它可能很好地询问哪个版本的IE失败了?)