多读jQuery.val()到数组 [英] Read multiple jQuery.val() into array
本文介绍了多读jQuery.val()到数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些code,看起来像这样的作品就好了:
VAR信息= [];
对于(I = 0; I&小于10;我+ +)
{
信息[I] = $('#info_'+ I).VAL();
}
的问题是,这种模式是很常见的我的一些较小的变化的应用程序。
我想要做的是使成oneliner这样的事情,其中的信息成为一个数组这样的:
VAR信息= $('[ID ^ =_信息]')每()VAL()。
解决方案
找到了解决的感谢Dogbert。所有这一切都在他的榜样缺失是获得()
下面是我结束了使用的解决方案:
VAR信息= $('[ID ^ =资讯_]')图(函数(){返回$(本).VAL();})得到(。 );
I have some code that looks like this that works just fine:
var info = [];
for (i = 0; i < 10; i++)
{
info[i] = $('#info_' + i).val();
}
The problem is that this pattern is very common in my application with some minor variations. What i would like to do is to make this into a oneliner something like this where info becomes an array:
var info = $('[id^="info_"]').each().val();
解决方案
Found a solution thanks to Dogbert. All that was missing in his example was the .get()
Here is the solution i ended up using:
var info = $('[id^="info_"]').map(function () { return $(this).val(); }).get();
这篇关于多读jQuery.val()到数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文