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

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

如何自动调整 jQuery UI 的大小Internet Explorer 中的对话框?

此代码在 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。

最佳答案

我使用以下“补丁”(适用于 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 - 在 Internet Explorer 中自动调整 jQuery UI 对话框的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4265316/

相关文章:

javascript - Jquery 更新循环内的 div 并显示所有值

jquery 自动完成在 chrome 中输入键(被劫持?) vs firefox

javascript - 将 XML 导入 HTML

java - 如何使用 javascript 在 Android 版 Google Chrome 中获得固定地址栏

javascript - CSS 图像右对齐 - Firefox 6.02 中的额外行

jQuery验证插件刷新IE8

javascript - jQuery UI 模态确认对话框中取消按钮的名称有什么神奇之处吗?

jquery - 如何设置 jquery 日期选择器的默认大小?

当我们移动到下一个选项卡时,jquery ui 选项卡需要清空上一个选项卡

Internet Explorer 9 rc1 中的 jQuery UI 对话框错误