如何获得具有索引​​值的元素的高度

时间:2014-02-15 12:36:59

标签: jquery

$(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 个答案:

答案 0 :(得分: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);
    })
});