我有一个序列化表单的麻烦
<form> <input type="text" name="name1" value="value1"/> <input type="text" name="name2" value="value2"/> </form> $(form).serializeArray()
将返回[{name:“name1”,value:“value1”},{name:“name2”,value:“value2”}]
是否可以获得输出的形式
{name1:value1,name2:value2}
这样他们更容易处理?
解决方法
var result = { }; $.each($('form').serializeArray(),function() { result[this.name] = this.value; }); // at this stage the result object will look as expected so you could use it alert('name1 = ' + result.name1 + ',name2 = ' + result.name2);