在数组中循环,jQuery返回undefined
Loop through an array with jQuery returning undefined
我试图在数组中循环并返回数据,只是我似乎无法返回数据,我收到了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
,因为people
是Array
使用people[i].name
相关文章:
- jquery返回边距为0的绝对中心
- 如何使用jquery返回php-json数组对象
- Firefox使用JQuery返回不正确的JSON
- 当jQuery返回错误时,如何在jQuery中重新发送ajax请求
- jquery返回ajax响应和用户定义的变量到函数
- 如何从ajax调用JQuery返回数据
- 单击按钮时Jquery返回到父函数
- jQuery返回prevObject..有时
- 使用String.FromCharCode时,jQuery返回未定义的结果
- jQuery返回多个函数;不起作用
- 正在读取嵌套json,jquery返回undefined
- IE使用类jquery返回相同的最后一个单选按钮值
- 在数组中循环,jQuery返回undefined
- 从php向jquery返回jsonencode错误
- .children()不适用于jquery返回的指定索引
- HTML 复选框 Click() 使用 jQuery 返回 FALSE 或 TRUE,而不是 READONLY 或 DI
- 使用 jQuery 返回除 Drupal7 表单之外的所有点击事件的消息
- 排序 Jquery 返回的 HTML 元素
- jQuery 返回空字符串作为 ID 表示
- jQuery返回所有页面已禁用,然后启用