【发布时间】:2013-03-20 18:55:26
【问题描述】:
我有一系列字段,例如:
<div class="field-label-inline">
<div class="field-label">something1</div>
<div class="field-items">
<div class="field-item">sometext1</div>
</div>
</div>
<div class="field-label-inline">
<div class="field-label">something2</div>
<div class="field-items">
<div class="field-item">sometext2</div>
</div>
我想让 .field-label div 的所有实例与相邻的 .field-items div 具有相同的高度(此 div 的高度根据其内容而异)。可悲的是,我的 jQuery 几乎不存在;这是我最好但失败的尝试:
$(document).ready(function(){
$('.field-label-inline > .field-label', this).each(function(){
var itemsHeight = 0;
itemsHeight = $(this + .field-items).height();
$(this).height(itemsHeight);
});
});
【问题讨论】:
-
为什么不能只使用 CSS?
-
使用 .height().api.jquery.com/height
标签: jquery containers