gpt4 book ai didi

javascript - 获取div组的最大高度

转载 作者:太空宇宙 更新时间:2023-11-03 19:49:13 27 4
gpt4 key购买 nike

我需要找到一组类名为 termPanel 的 div 中最大的 div 的高度。如何访问术语数组中的每个“termPanel”div?

 function resizePanelsToBiggest(){

var maxheight = 0;

var terms = $('.termPanel');

for(var i = 0;i<terms.length;++i){

if(maxheight < terms[i].height){
maxheight = terms[i].height;
}


}

}

最佳答案

使用Math.max.apply

function resizePanelsToBiggest() {
var maxheight = 0;
var terms = $('.termPanel');
var allH = terms.map(function() {
return $(this).height();
}).get();
var maxH = Math.max.apply(null, allH);
console.log(maxH);
}

关于javascript - 获取div组的最大高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40363128/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com