简体   繁体   English

窗口高度jQuery函数返回未定义的值

[英]Window height jquery function returns undefined value

$(window).height(); $(窗口).height(); returns no values says its undefined. 不返回任何值表示其未定义。

                         var modalHeight = $(window).height();

                        $('.inside-body-wrapper').css("max-height",modalHeight);
                        $('.overlay').css("height",modalHeight);
                        $('.modal').css({
                            display: "block",
                            height: modalHeight
                        });

下面是控制台的屏幕截图。

You can use.. 您可以使用..

$(document).ready(function() {     

  var wt = $(window).width();
  var ht = $(window).height();
  ....
  ....    
});

The reason is clear if you think about what jquery actually does, it's returning the height style property for whatever you give the selector. 原因很清楚,如果您考虑一下jquery的实际作用,则将为选择器提供的内容返回height样式属性。 As window doesn't have that it will be undefined. 由于window没有,它将是未定义的。

You could instead try using window.outerHeight or window.innerHeight to get those properties instead which could be useful. 您可以尝试使用window.outerHeight或window.innerHeight来获取那些有用的属性。

您可以使主体标记为100%高度,然后获得主体的高度而不是窗口的高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM