ami*_*mit 13 javascript jquery
我想找出了给予<li>其li具有最大高度?我该怎么写这样的功能?
如果有n <li>个不同大小,内容和高度的元素.我想弄清楚最大<li>元素的最大高度.
Igo*_*mov 29
试试这个:
var max = -1;
$("li").each(function() {
var h = $(this).height();
max = h > max ? h : max;
});
alert(max);
Run Code Online (Sandbox Code Playgroud)
Dog*_*ert 20
如果你想要一个衬垫
var max = Math.max.apply(Math, $("li").map(function() { return $(this).height(); }))
Run Code Online (Sandbox Code Playgroud)
var liMaxHeight = -1;
var node;
$("li").each(function(index) {
if ($(this).outerHeight() > liMaxHeight) {
liMaxHeight = $(this).outerHeight();
node = index;
}
});
alert("li with index " + node + " has height " + liMaxHeight);
Run Code Online (Sandbox Code Playgroud)
.outerHeight()包括填充和边框.如果不想包括填充和边框使用height()
| 归档时间: |
|
| 查看次数: |
26446 次 |
| 最近记录: |