我需要检查每个父div,找到最高的子div,并将高度应用于除了同一父div之外的所有子div。
html:<div class="parent">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
jquery不工作在我的html:
var maxHeight = -1;
$('.parent>.child').each(function() {
maxHeight = maxHeight > $(this).height() ? maxHeight : $(this).height();
});
$('.child').each(function() {
$(this).height(maxHeight);
});
有人能帮忙吗?
尝试先遍历每个rows
,然后检查其children
元素,
var maxHeight = -1;
$('.parent').each(function() {
$(this).children(".child").each(function(){
maxHeight = maxHeight > $(this).height() ? maxHeight : $(this).height();
}).height(maxHeight);
maxHeight = -1;
});
需要分别循环每个.parent
$('.parent').each(function () {
var maxHeight = -1;
var $children = $(this).children('.child');
$children.each(function () {
maxHeight = maxHeight > $(this).height() ? maxHeight : $(this).height();
});
$children.height(maxHeight);
})