【发布时间】:2012-03-29 10:37:33
【问题描述】:
谁能告诉我为什么下面给了我一个空字符串?当我在$.get() 回调函数中console.log(contentArray) 时,它会显示数据,但是当我尝试在下面代码中的位置执行此操作时,结果为空。
sectionArray = [];
contentArray = [];
$(function () {
if (index == 1) {
$('menu:eq(' + (section - 1) + ') li a').each(function () {
sectionArray.push($(this).attr('href'));
});
var len = sectionArray.length;
for (var i = 0; i < len; i++) {
href2 = sectionArray[i];
$.get(href2, function (data) {
string = data.toString();
contentArray.push(string);
});
}
content = contentArray.toString();
console.log(content);
}
【问题讨论】:
标签: javascript jquery