使用jQuery返回匹配元素的属性ar数组 [英] Return matched elements' attribute ar array using jQuery
本文介绍了使用jQuery返回匹配元素的属性ar数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在jQuery中,很容易选择元素作为数组。
In jQuery, it is easy to select elements as array.
$(a); //作为元素数组返回
$("a"); // return as elements array of anchors
但是可以选择匹配元素属性作为数组?
But is it possible to select matched elements' attributes as array?
目前我需要做类似的事情......
Currently I need to do something like...
links = [];
links = [ ];
$(a)。each(function(){
$("a").each(function() {
href = $(this).attr("href");
links.push(href);
});
有没有更好的方法来填充变量链接所有匹配的锚点的href?
Are there any better method to fill the variable links with href of the all matched anchors?
推荐答案
像这样使用$ .map:
Use $.map like so:
var links = $('a').map(function() { return this.href }).get()
这篇关于使用jQuery返回匹配元素的属性ar数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文