获取值数组使用JQuery? [英] Get array of values use JQuery?
本文介绍了获取值数组使用JQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:结果
如何让所有的ID的使用jQuery?
块引用>我怎样才能获得值数组里面的属性ID跨度ID =启用,如果使用jQuery?
<跨度ID =启用>
&LT,P n ='105'>英语< / P>
&LT,P n ='250'>西班牙语< / P>
&LT,P n ='56'>德语< / P>
< / SPAN>
<跨度ID ='禁用'>
&LT,P n ='38'>&BLABLA LT; / P>
&LT,P n ='46'> BlaBla2< / P>
&LT,P n ='87'> BlaBla3< / P>
< / SPAN>
解决方案您可以使用jQuery的
数组地图
功能。这将返回英语,西班牙和德国。VAR myArray的= $('#使P')。图(函数(){
返回$(本)的.text();
})。得到();有关获得标识的列表,你可以做到这一点。
VAR myArray的= $('#使P')。图(函数(){
返回this.id;
})。得到();请参阅的jsfiddle http://jsfiddle.net/B3LuE/
Possible Duplicate:
How to get all of the IDs with jQuery?How can i get array of values attribute ID inside "span id='enable'" if i use JQuery?
<span id='enable'> <p id='105'>English</p> <p id='250'>Spanish</p> <p id='56'>German</p> </span> <span id='disable'> <p id='38'>BlaBla</p> <p id='46'>BlaBla2</p> <p id='87'>BlaBla3</p> </span>
解决方案You can use Jquery's
map
function. This will return array of "English","Spanish" and "German".var myArray = $('#enable p').map(function(){ return $(this).text(); }).get();
For getting Id's list you can do this
var myArray = $('#enable p').map(function(){ return this.id; }).get();
See jsfiddle http://jsfiddle.net/B3LuE/
这篇关于获取值数组使用JQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文