如何解析input []值并将它们放入Javascript数组中 [英] How to parse input[] values and put them into a Javascript Array
本文介绍了如何解析input []值并将它们放入Javascript数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我说我有这个:
<form id='foo'>
<input name='bar[name]' />
<input name='bar[age]' />
</form>
如何在 foo格式中获取数组输入的值
并将它们放入一个关联数组/对象中,如下所示:
How can i get the values of array inputs within the form foo
and put them into an associative array/object like this:
var result = {bar:{name:'blah',age:21}};
P.S。我不想为此使用任何框架。
P.S. I don't want to use any frameworks for this.
推荐答案
这将为您提供以下元素:
This will get you the elements:
var result = {};
var elements = document.forms.foo.getElementsByTagName("input");
for(var i = 0; i < elements.length; i++)
{
/* do whatever you need to do with each input */
}
这篇关于如何解析input []值并将它们放入Javascript数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文