如何自动调整 jQuery UI 的大小Internet 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。
最佳答案
我使用以下“补丁”(适用于 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' 但我就是不能没有它......:)
关于jquery - 在 Internet Explorer 中自动调整 jQuery UI 对话框的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4265316/