1

我需要使用 jQuery 为每个页面动态添加 css 高度。

到目前为止,我得到了以下代码,但它没有向#wrapper 添加高度。

function getPageSizeWithScroll(){
if (window.innerHeight && window.scrollMaxY) {// Firefox
    yWithScroll = window.innerHeight + window.scrollMaxY;
    xWithScroll = window.innerWidth + window.scrollMaxX;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    yWithScroll = document.body.scrollHeight;
    xWithScroll = document.body.scrollWidth;
} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    yWithScroll = document.body.offsetHeight;
    xWithScroll = document.body.offsetWidth;
}
arrayPageSizeWithScroll = yWithScroll;
//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
return arrayPageSizeWithScroll;
}
var newheight = getPageSizeWithScroll() + 30;

$('#wrapper').css({'height':'newheight'});
4

6 回答 6

10

尝试

$('#wrapper').css("height", newheight);
于 2009-07-03T07:43:36.277 回答
2

您将高度设置为字符串“newheight”,而不是 newheight 的值。只需摆脱引号:

$('#wrapper').css({'height':newheight});
于 2009-07-03T07:43:20.490 回答
2

或者

$('#wrapper').css({height:newheight+'px');
于 2009-07-03T09:09:39.100 回答
2

这应该有效:

$('#wrapper').css({'height':newheight});
于 2010-01-08T15:04:49.523 回答
2

您正在为您的身高分配一个字符串值,您只需要删除引号并简单地放置一个包含值的变量。像

var newheight = getPageSizeWithScroll() + 30;

$('#wrapper').css('height':newheight);
于 2014-01-29T06:11:09.837 回答
0

或者

$('#wrapper').height(newheight);

有很多方法可以做同样的事情。 高度法

于 2009-07-03T13:09:07.327 回答