jQuery jQueryUI 对话框宽度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23847635/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 02:23:33  来源:igfitidea点击:

jQueryUI dialog width

jqueryhtmlcssjquery-ui

提问by RedGiant

Fiddle Full Screen Example

小提琴全屏示例

I use jQuery dialog to open tables. Some of them have a large amount of text and they tend to be too long and go way off the screen. How can I make the dialog wider if the table is too long like the first one in the fiddle? I've tried width:'auto'but it seems to just occupy the entire screen.

我使用 jQuery 对话框打开表格。其中一些有大量文本,而且它们往往太长并且离屏幕很远。如果表格像小提琴中的第一个表格一样太长,如何使对话变宽?我试过了,width:'auto'但它似乎只占据了整个屏幕。

HTML:

HTML:

<button class='label'>Click</button><div class='dialog'><p><table>.....</table></div>
<button class='label'>Click</button><div class='dialog'><p><table>.....</table></div>

Javascript:

Javascript:

$(document).ready(function(){

 $('.label').each(function() {

 var dialogopen = $(this).next(".dialog"); 
 dialogopen.dialog({width:'auto',autoOpen: false,modal: true,
            open: function(){
            jQuery('.ui-widget-overlay').bind('click',function(){
                dialogopen.dialog('close');
            })
        }    
 });    
  $(this).click(function(){
        dialogopen.dialog('open');
         return false;
            }
        );
  });
});

回答by Rodney Golpe

I'd suggest adding widthand maxWidthto your dialog options. I don't know what your design looks like, but try something like this, for example:

我建议将width和添加maxWidth到您的对话框选项中。我不知道你的设计是什么样的,但试试这样的东西,例如:

dialogopen.dialog({
   autoOpen: false,
   modal: true,
   open: function(){
      jQuery('.ui-widget-overlay').bind('click',function(){
         dialogopen.dialog('close');
      });
   },
   width: "90%",
   maxWidth: "768px"
});