【发布时间】:2015-03-07 22:30:00
【问题描述】:
我创建了一个循环遍历一组产品的函数,并将其复制区域的高度设置为该组中最高复制区域的高度。
这是我的代码:
function productCopyHeight(){
//make sub range product text sections the same height
if($('.sub-range').length){
$('.sub-range').each(function(){
var itemHeight = 0;
$(this).children('.product-item').children('.copy').each(function(i){
var thisItemHeight = $(this).height();
console.log(thisItemHeight + ' > ' + itemHeight)
if(thisItemHeight > itemHeight){
var itemHeight = thisItemHeight;
}
});
$(this).children('.product-item').children('.copy').css('height', itemHeight);
})
}
}
当我记录它时,当它在每个循环之前定义时,它显示 itemHeight 变量为未定义。
【问题讨论】:
-
itemHeight未定义在哪一行? -
console.log的输出是什么? -
控制台输出是'44 > undefined'