Jquery 将PX添加回div高度
我正在编写一些jquery,它获取2个div的高度,并将另一个div设置为组合高度Jquery 将PX添加回div高度,jquery,Jquery,我正在编写一些jquery,它获取2个div的高度,并将另一个div设置为组合高度 var height1 = $("#heightSelector2").height(); var height2 =$("#heightSelector3").height(); var maxHeight = height1 + height2; console.log(maxHeight); 现在如何设置$(“#heighSelector1”)=maxHeight? 我知道我还需要把px加进去,我看过一
var height1 = $("#heightSelector2").height();
var height2 =$("#heightSelector3").height();
var maxHeight = height1 + height2;
console.log(maxHeight);
现在如何设置$(“#heighSelector1”)=maxHeight?
我知道我还需要把px加进去,我看过一些例子,但还不够清楚
$("#heightSeletor1").height(maxHeight + "px")
老实说,我认为您不需要将px
添加回去,但如果需要,只需使用+
操作符将其追加即可
老实说,我认为您不需要将
px
添加回去,但如果需要,只需使用+
操作符将其追加即可。您无需添加px
试试这个
$("#heightSeletor1").height(maxHeight)
示例:$(选择器)。高度(30)代码>
您无需添加px
试试这个
$("#heightSeletor1").height(maxHeight)
示例:$(选择器)。高度(30)代码>
这里有另一种方法
$(“#heightSelector1”).css(“height”,maxHeight+“px”)代码>这里是另一种方法
$(“#heightSelector1”).css(“height”,maxHeight+“px”)代码>您可以使用不带+px:$(“#heightSeletor1”).height(maxHeight)的示例;您还可以使用$(“#heightSeletor1”).css(“height”,maxHeight+“px”);在这个例子中,你确实需要+“px”@CatalinDeaconescu,但我已经在我的帖子中提到了。很抱歉,Evan,我在发布之前没有看到更新。你可以使用没有+px:$(“#heightSeletor1”).height(maxHeight)的例子;您还可以使用$(“#heightSeletor1”).css(“height”,maxHeight+“px”);在本例中,您确实需要+“px”@CatalinDeaconescu,但我已经在我的帖子中提到了。很抱歉,Evan,我在发布之前没有看到更新