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

これは機能するはずです:

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

また

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

身長に文字列値を割り当てています。引用符を削除して、値を含む変数を単純に配置するだけです。お気に入り

var newheight = getPageSizeWithScroll() + 30;

$('#wrapper').css('height':newheight);
于 2014-01-29T06:11:09.837 に答える
2

newheight の値ではなく、文字列 'newheight' に高さを設定しています。引用符を取り除くだけです:

$('#wrapper').css({'height':newheight});
于 2009-07-03T07:43:20.490 に答える
0

または

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

同じことをする方法はたくさんあります。 高さ法

于 2009-07-03T13:09:07.327 に答える