87,993
社区成员
发帖
与我相关
我的任务
分享 var maxLen = [0];
$("ul>li").each(function() {
var index = $(this).index();
if (maxLen.length<index+1)
{
maxLen.push(0);
}
if ($(this).height()>maxLen[index])
{
maxLen[index]=$(this).height()
}
})
var alls = []
for (var i = 0 ; i < maxLen.length ; i++) {
$('ul>li:eq('+i+')').css('height',maxLen[i]+'px')
}
<html>
<body>
<ul>
<li style="height:30px;">11</li>
<li>12</li>
<li>13</li>
</ul>
<ul>
<li>21</li>
<li style="height:32px;">22</li>
<li>23</li>
<li style="height:22px;">24</li>
</ul>
<ul>
<li>31</li>
<li style="height:42px;">32</li>
<li>33</li>
</ul>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
var maxLen = 0
$("ul>li").each((i, o) => {
maxLen = Math.max($(o).index(), maxLen)
})
var alls = []
for (let i = 0; i <= maxLen; i++) {
var arr = []
$("ul").each((i2, o) => {
var li = $(">li", o).eq(i)
if (li.length) {
arr.push(li)
}
})
alls.push(arr)
}
alls.forEach(item => {
var theMax = Math.max.apply(null, item.map(li => li.height()))
item.forEach(li => {
li.height(theMax)
})
})
</script>
</body>
</html>
var max_height=0;
$('ul>li').each(function(){
if ($(this).height()>max_height){
max_height = $(this).height();
}
})
$('ul>li').css('height',max_height+'px')