2014-02-15 28 views
0
$(document).ready(function() { 
    var autoHeight = ''; 
    var items = $('.iosSlider .slider .item'); 
    var CountNumber = items.size(); 
    var sliderHeight = 0; 
    for (var i = 0; i <= CountNumber - 1; i++) { 
     alert('hi') var itemBox = items.eq[i]; 
     var itemHeight = itemBox.height(); 
     alert(itemHeight); 
    } 
}); 

回答

1

.eq()是一個函數,所以通過使用()調用它 - 所以用items.eq(i)代替items.eq[i]

$(document).ready(function() { 
    var autoHeight = ''; 
    var items = $('.iosSlider .slider .item'); 
    var CountNumber = items.size(); 
    var sliderHeight = 0; 
    for (var i = 0; i < CountNumber; i++) { 
     alert('hi'); 
     var itemBox = items.eq(i); 
     var itemHeight = itemBox.height(); 
     alert(itemHeight); 
    } 
}); 

你也可以看看.each()方法遍歷jQuery對象,如

$(document).ready(function() { 
    var autoHeight = ''; 
    var items = $('.iosSlider .slider .item'); 
    var sliderHeight = 0; 
    items.each(function (i, item) { 
     alert('hi'); 
     var itemBox = $(this) 
     var itemHeight = itemBox.height(); 
     alert(itemHeight); 
    }) 
}); 
相關問題