我正在编写一些jquery,它获得2个div的高度并将另一个div设置为组合高度。
var height1 = $("#heightSelector2").height();
var height2 =$("#heightSelector3").height();
var maxHeight = height1 + height2;
console.log(maxHeight);
我现在如何设置$(“#heighSelector1”)= maxHeight? 我知道我还需要在那里添加px,我已经看到了一些例子,但还不够清楚。
答案 0 :(得分:5)
$("#heightSeletor1").height(maxHeight + "px")
说实话,我认为您不需要添加px
,但如果您这样做,只需使用+
运算符即可添加。
答案 1 :(得分:1)
答案 2 :(得分:1)
这是另一种方法。
$("#heightSelector1").css("height",maxHeight + "px");