$(".box-services-c h4").each(function () {
var getHeightHfour = $(this).height();
console.log(getHeightHfour);
var smallHeight = 18;
var bigHeight = 36;
if(getHeightHfour == smallHeight) {
$(".box-services-c h4").addClass('small')
}
if(getHeightHfour == bigHeight) {
$(".box-services-c h4").addClass('big')
}
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="box-services-c">
<h4>SPANNAX®<br>Spannfutter</h4>
</div>
<div class="box-services-c">
<h4>Spannfutter</h4>
</div>
&#13;
答案 0 :(得分:2)
使用$(this)引用每个函数内的匹配元素:
if(getHeightHfour == smallHeight) {
$(this).addClass('small')
}
if(getHeightHfour == bigHeight) {
$(this).addClass('big')
}