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 です。

4

2 に答える 2

5

width: 'auto'次の「パッチ」(IE用)を使用して、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' を使用すべきではないことに注意してください。

于 2010-12-14T20:54:50.893 に答える
0

,まず、次の行の最後にa を追加してください

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

IEは、すべてのオプションが次の方法で閉じられることを期待しています,

これで問題が解決するかどうか見てみましょう (これが失敗している IE のバージョンを尋ねるのはおそらく良いことでしょう)。

于 2010-11-24T16:21:58.823 に答える