基于屏幕宽度和高度的 jQuery UI 对话框宽度和高度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4726327/
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-26 17:49:51  来源:igfitidea点击:

jQuery UI dialog width & height based on screen width & height

jqueryjquery-ui

提问by Jason

Currently (jQuery 1.4.4 and UI 1.8.8) I used the following to set a dialog's properties: (I'm trying to set the dialog to be 180px less than the height and width of the screen.)

目前(jQuery 1.4.4 和 UI 1.8.8)我使用以下内容来设置对话框的属性:(我试图将对话框设置为比屏幕的高度和宽度小 180px。)

$("#dialog").dialog({ 
            bgiframe: true,
            position: 'center',
            width: $(window).width()-180,
            height: $(window).height()-180,
            title: ititle,
            modal: true,
            buttons: { "Close": function() { $(this).dialog("destroy"); }}
});

The above works fine in FF but in IE 8 it fails.

以上在 FF 中工作正常,但在 IE 8 中失败。

Is this the right way to set width and height or should I be doing something differently?

这是设置宽度和高度的正确方法还是我应该做一些不同的事情?

采纳答案by Gregg

You probably need to specify the DOCTYPE and use standards mode for it to work correctly.

您可能需要指定 DOCTYPE 并使用标准模式才能使其正常工作。

回答by usr-bin-drinking

This worked for me in IE8:

这在 IE8 中对我有用:

var winW = $(window).width() - 180;
var winH = $(window).height() - 180;

$( "#dialog" ).dialog({
    autoOpen: false,
    height: winH,
    width: winW,
    modal: true
});

You'll need this at the top of your page though

不过,您需要在页面顶部使用它

<!DOCTYPE html>