我需要一个jQuery函数来搜索具有相同类的元素列表,并返回最高元素的高度。
任何帮助都会很棒。
答案 0 :(得分:15)
var maxHeight = 0;
$('.myclass').each(function(){
maxHeight = $(this).height() > maxHeight ? $(this).height() : maxHeight;
});
alert(maxHeight);
或者:
var maxHeight = Math.max.apply(null, $('.myclass').map(function () {
return this.clientHeight; // or $(this).height()
}));
答案 1 :(得分:3)
试试这个:
var maxHeight = 0;
$('.whatever').each(function () {
maxHeight = Math.max($(this).height(), maxHeight);
});