我有一个函数,我用来在页面上创建equalheight所有相同高度(最高元素的高度)的元素:
equalheight = function(container){
var currentTallest = 0,
currentRowStart = 0,
rowDivs = new Array(),
$el,
topPosition = 0;
$(container).each(function() {
$el = $(this);
$($el).height('auto')
topPostion = $el.position().top;
if (currentRowStart != topPostion) {
for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
rowDivs[currentDiv].height(currentTallest);
}
rowDivs.length = 0; // empty the array
currentRowStart = topPostion;
currentTallest = $el.height();
rowDivs.push($el);
} else {
rowDivs.push($el);
currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
}
for (currentDiv = 0 …Run Code Online (Sandbox Code Playgroud) 我有一个 div 并且不止一个数据通过 jstl 标签进入这个 div。我想找到最大内容 div 高度。我看到了一个链接,但它每次都显示在警报中 20. 具有一组元素中最大高度的元素
JSP
<div id="div-height" class='cat-product-name'>${i.name} </div>
Run Code Online (Sandbox Code Playgroud)
爪哇脚本
$(window).load(function () {
var maxHeight = Math.max.apply(null, $("#div-height").map(function ()
{
return $(this).height();
}).get());
alert(maxHeight);
});
Run Code Online (Sandbox Code Playgroud)
我想找到 div 的最大高度并设置每个 div 的高度。