我认为这是一个非常简单的问题,但…
var outerHeight = $('.profile').outerHeight(); $("#total-height").text(outerHeight + 'px');
现在,var outerHeight给我的只有第一个元素的外部程序类.profile。
如何使用.profile类获取所有元素的outerHeights的总和?
解决方法@H_404_10@
循环遍历每个匹配元素,并加上外部高度:
var outerHeight = 0;
$('.profile').each(function() {
outerHeight += $(this).outerHeight();
});
$("#total-height").text(outerHeight + 'px');
var outerHeight = 0; $('.profile').each(function() { outerHeight += $(this).outerHeight(); }); $("#total-height").text(outerHeight + 'px');