从jQuery集合中获取每个元素的属性值,并放入一个数组中 [英] Get the attribute value of each element from a jQuery set, into an array
本文介绍了从jQuery集合中获取每个元素的属性值,并放入一个数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取与jQuery选择器匹配的所有元素的所有属性(例如href
)?
How can I get all attributes (e.g. href
) of all elements matching a jQuery selector?
推荐答案
也许是这样的事情?
var ids = [];
$('.myClass').each(function () {
ids.push($(this).attr('id')); // ids.push(this.id) would work as well.
});
这篇关于从jQuery集合中获取每个元素的属性值,并放入一个数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文