我刚刚使用 JQuery 1.4.1 和 UI 1.8rc1 编写了一个小型示例应用程序。我所做的只是将构造函数指定为:
var theDialog = $(".mydialog").dialog({
autoOpen: false,
resizable: false,
modal: true,
width:'auto'
});
我知道你说过这会使其占据浏览器窗口 100% 的宽度,但它在这里工作得很好,在 FF3.6、Chrome 和 IE8 中进行了测试。
我没有进行 AJAX 调用,只是手动更改对话框的 HTML,但不认为这会导致任何问题。其他一些 css 设置可以解决这个问题吗?
唯一的问题是它使宽度偏离中心,但我发现这个支持票 http://dev.jqueryui.com/ticket/4053他们提供了一种解决方法,将dialog('open')
setTimeout 中的语句来解决问题。
这是我的 head 标签的内容:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery-ui.min.js"></script>
<link href="jquery-ui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function(){
var theDialog = $(".mydialog").dialog({
autoOpen: false,
resizable: false,
modal: true,
width: 'auto'
});
$('#one').click(function(){
theDialog.html('some random text').dialog('open');
});
$('#two').click(function(){
theDialog.html('<ul><li>Apple</li><li>Orange</li><li>Banana</li><li>Strawberry</li><li>long text string to see if width changes</li></ul>').dialog('open');
});
$('#three').click(function(){
//this is only call where off-centre is noticeable so use setTimeout
theDialog.html('<img src="./random.gif" width="500px" height="500px" />');
setTimeout(function(){ theDialog.dialog('open') }, 100);;
});
});
</script>
我从以下位置下载了 Jquery UI 的 js 和 csshttp://jquery-ui.googlecode.com/files/jquery-ui-1.8rc1.zip http://jquery-ui.googlecode.com/files/jquery-ui-1.8rc1.zip。
和身体:
<div class='mydialog'></div>
<a href='#' id='one'>test1</a>
<a href='#' id='two'>test2</a>
<a href='#' id='three'>test3</a>