在Internet Explorer中自动调整jQuery UI对话框的大小 [英] Auto size a jQuery UI dialog in Internet Explorer

查看:92
本文介绍了在Internet Explorer中自动调整jQuery UI对话框的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在互联网资源管理器中自动调整 jQuery UI 对话框?

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

这段代码在Firefox中没问题,但在Internet资源管理器中没有。

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(); } }
});

我的HTML元素是DIV。

My HTML element is a DIV.

推荐答案

我用宽度成功:'auto'使用以下补丁(对于IE)调整jQuery UI对话框的大小:

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);

只需在加载jquery-ui.js后加载此代码...

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

请注意,根据机票 http://dev.jqueryui.com/票/ 4437 我们不应该使用宽度:'auto'但是我不能没有它...... :)。

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 ... :)

这篇关于在Internet Explorer中自动调整jQuery UI对话框的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆