2列布局的高度相等,但每行的高度不同

时间:2014-01-12 00:54:27

标签: javascript jquery css

我使用js使2列具有相同的高度。左列是用户的输入,因此它是动态的,有时候它有更多的内容或更少。我的问题是我有很多行而不是一行。我想使用each()循环并应用于每一行,但我在标记上的类名是相同的。

boxes = $('.heightHack'); maxHeight = Math.max.apply( Math, boxes.map(function() { return $(this).height(); }).get()); boxes.height(maxHeight);

demo http://bootply.com/105122

1 个答案:

答案 0 :(得分:0)

将其包裹在循环上并使用.find()

$(".container").each(function(){
   boxes = $(this).find('.heightHack');
   maxHeight = Math.max.apply(
     Math, boxes.map(function() {
       return $(this).height();
   }).get());
   boxes.height(maxHeight);
});

演示:http://bootply.com/105123

希望这会有所帮助。干杯