如何存储从下面的 Jquery 接收的数据以供进一步使用。
$('#div').find('a').each(function() {
console.log($(this).attr('href'));
});
http://jsfiddle.net/mvm6o208/你可以在这里找到我的代码。
最佳答案
创建一个数组并将值推送到它。喜欢
var store = [];
$('#div').find('a').each(function() {
store.push($(this).attr('href'));
});
更新:根据您发布的 fiddle 中的 html,选择器应该是 $('div').find('a')
而不是 $('#div ').find('a')
,因为您没有任何 ID 为 div
的 div。查看工作 fiddle here .
也根据 the inputs从下面的评论中,通过
推送到数组会更快store[store.length] = $(this).attr('href');
关于javascript - JQuery - 如何存储收到的每个数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26276840/