V S*_* SH 2 javascript jquery jsp jstl
我有一个 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 的高度。
你可以试试这个:-
$(document).ready(function() {
var maxHeight = -1;
$('.cat-product-name').each(function() {
maxHeight = maxHeight > $(this).height() ? maxHeight : $(this).height();
});
$('.cat-product-name').each(function() {
$(this).height(maxHeight);
});
});
Run Code Online (Sandbox Code Playgroud)