使用jQuery从元素选择中获取属性值作为数组 [英] Get attribute values as array from selection of elements using jQuery
本文介绍了使用jQuery从元素选择中获取属性值作为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用jQuery有以下内容:
I have the following using jQuery:
var x = $('.boxes > input:checked');
我试图从x中检索一个id值数组,但无法弄清楚该怎么做.
From x I am trying to retrieve an array of id values and have been unable to work out how to do this.
类似的东西:
var y = x[id];
// y becomes an array like ['1', '2', '3'] assuming
// that x had 3 checkboxes with id's of 1, 2, 3 etc.
推荐答案
您可以使用 jQuery.map :
var x = $('.boxes > input:checked');
var y = $.map(x, function (element){
return element.id;
});
y
变量将是一个包含元素ID的数组.
The y
variable, will be an array containing the element ids.
这篇关于使用jQuery从元素选择中获取属性值作为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文