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

2023-12-22

我怎样才能自动调整大小jQuery用户界面 http://en.wikipedia.org/wiki/JQuery_UIInternet 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。


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

(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 http://dev.jqueryui.com/ticket/4437我们不应该使用 width: 'auto' 但我就是不能没有它......:)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐