将PX添加回div高度

Ant*_*ony 1 jquery

我正在写一些jquery,它获得2个div的高度并将另一个div设置为组合高度.

var height1 = $("#heightSelector2").height();
var height2 =$("#heightSelector3").height();
var maxHeight = height1 + height2;
console.log(maxHeight); 
Run Code Online (Sandbox Code Playgroud)

我现在如何设置$("#heighSelector1")= maxHeight?我知道我还需要在那里添加px,我已经看到了一些例子,但还不够清楚.

Wha*_*ied 5

$("#heightSeletor1").height(maxHeight + "px")
Run Code Online (Sandbox Code Playgroud)

说实话,我不相信你需要添加px背面,但如果你这样做,只需使用+运算符来追加它.