2010-11-24 85 views
6

如何在互联网  Explorer中自动调整对话框jQuery UI在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。

+0

你使用的是什么版本的jQuery和jQuery UI? – 2010-11-29 13:18:05

+0

jquery ui 1.8.5 JQuery 1.4.2 – Shahin 2010-11-29 16:44:03

回答

0

请首先在以下行

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

IE期望所有选项被关闭的末尾添加,通过,

让我们来看看如果这样做的伎俩(它可能是很好的问什么版本的IE是这个失败?)

+0

我使用IE 8 – Shahin 2010-11-25 07:21:47

5

我成功与width: 'auto'使用以下“补丁”(对于IE)调整jQuery UI对话框:

jQuery的ui.js加载后
(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); 

只加载此代码...,根据票http://dev.jqueryui.com/ticket/4437我们不应该使用宽度

注:“自动”,但我只是不能活没有它... :)

相关问题