jQuery 求最大元素的高度
jQuery Find height of the largest element
我有六个 div 都需要是身高最大的那一个。
例如,如果一个div里面有5行文字,而其他的都是2行,那么它们都需要拉伸以匹配5行文字的高度。
如何通过元素 类 做到这一点?
var mh=0;
$(".some-class-name").each(function () {
if (mh < $(this).height()) {
mh=$(this).height()
}
})
$(".some-class-name").height(mh);
$(document).ready(function(){
var el = $('.one'),
elHeight = [];
el.each(function(){
elHeight.push($(this).height());
});
el.height(Math.max.apply(Math, elHeight));
});
我有六个 div 都需要是身高最大的那一个。
例如,如果一个div里面有5行文字,而其他的都是2行,那么它们都需要拉伸以匹配5行文字的高度。
如何通过元素 类 做到这一点?
var mh=0;
$(".some-class-name").each(function () {
if (mh < $(this).height()) {
mh=$(this).height()
}
})
$(".some-class-name").height(mh);
$(document).ready(function(){
var el = $('.one'),
elHeight = [];
el.each(function(){
elHeight.push($(this).height());
});
el.height(Math.max.apply(Math, elHeight));
});