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

发布于 2024-10-04 07:42:44 字数 647 浏览 10 评论 0原文

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

How can I autosize a jQuery UI dialog in Internet Explorer?

This code is OK in Firefox, but not in 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(); } }
});

My HTML element is a DIV.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奶茶白久 2024-10-11 07:42:44

我使用以下“补丁”(适用于 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' 但我就是不能没有它......:)

I'm having success with width: 'auto' sizing jQuery UI dialog using the following "patch" (for 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);

Just load this code after jquery-ui.js has loaded ...

Note that according to the ticket http://dev.jqueryui.com/ticket/4437 we shouldn't be using width: 'auto' but I just couldn't live without it ... :)

2024-10-11 07:42:44

请首先在以下行的末尾添加 ,

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

IE 希望通过 , 关闭所有选项

让我们看看这是否能解决问题(最好问一下什么IE 版本是否会失败?)

Please first add a , at the end of the following line

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

IE expects that all options be closed off via ,

Let's see if that does the trick (its probably good to ask what version of IE is this failing on?)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文