在数组中循环,jQuery返回undefined

Loop through an array with jQuery returning undefined

本文关键字:jQuery 返回 undefined 循环 数组      更新时间:2023-10-28

我试图在数组中循环并返回数据,只是我似乎无法返回数据,我收到了undefined

http://jsfiddle.net/Liamatvenn/UvNw3/2/

我的阵列

var people = [{
    id: 0,
    name: 'Brian Nicoll'
}, {
    id: 1,
    name: 'Gordon Sales'
}, {
    id: 2,
    name: 'Lorman E. Correa'
}, {
    id: 3,
    name: 'Mark Moor'
}, {
    id: 4,
    name: 'Richard Paisley'
}, {
    id: 5,
    name: 'S. Sivalingham'
}, {
    id: 6,
    name: 'Tony Coleman'
}];
var counter = 0;
(function nextFade() {
    counter++;
    var figure = $('<figure style="float:left; width:130px; height:30px;" />');
    var information = '<figcaption><h6>Meet ' + people.name + '</h6></figcaption>';
    figure.html(information).appendTo('.interactive-banner-faces').hide().fadeIn(100, function () {
        if (counter < 7) {
            nextFade();
        } else {
            $('.interactive-banner-faces').children(':nth-child(12n+1), :nth-child(12n+2), :nth-child(12n+3)').addClass('rightTxt');
            $('.interactive-banner').on('mouseenter', function () {
                $('.textbox').css('z-index', '9999')
                $('.overlay').stop().animate({
                    'top': '-450px'
                }, 200, 'easeInCirc');
            }).on('mouseleave', function () {
                $('.textbox').css('z-index', '-1')
                $('.overlay').stop().animate({
                    'top': '0'
                }, 600, 'easeOutCirc');
            });
        }
    });
})();

您忘记放置索引people[counter].name

(function nextFade() {
        counter++;
        var figure = $('<figure style="float:left; width:130px; height:30px;" />');
        var information = '<figcaption><h6>Meet ' + people[counter].name + '</h6></figcaption>';
        figure.html(information).appendTo('.interactive-banner-faces').hide().fadeIn(100, function () {
            if (counter < 7) {
                nextFade();
            } else {
                $('.interactive-banner-faces').children(':nth-child(12n+1), :nth-child(12n+2), :nth-child(12n+3)').addClass('rightTxt');
                $('.interactive-banner').on('mouseenter', function () {

    $('.textbox').css('z-index', '9999')
                    $('.overlay').stop().animate({
                        'top': '-450px'
                    }, 200, 'easeInCirc');
                }).on('mouseleave', function () {
                     $('.textbox').css('z-index', '-1')
                    $('.overlay').stop().animate({
                        'top': '0'
                    }, 600, 'easeOutCirc');
                });
            }
        });
    })();

您使用未定义的people.name,因为peopleArray使用people[i].name