我得到了下面的HTMLTableRowElement。我需要根据name字段以及input和select元素的相应值将其转换为json。有没有库或jquery方法可以做到这一点?当对行的jquery对象进行调用时,jquery的serializeArray方法返回一个空数组,如$('the following HTMLTableRowElement').serializeArray()。
<tr id="row7">
<td>
<input type="text" id="person_row7" name="person_row7">
</td>
<td>
<input type="text" id="father_row7" name="father_row7">
</td>
<td>
<input class="input-mini" type="text" id="age_row7" name="age_row7">
</td>
<td>
<select id="gender_row7" class="input-small" name="gender_row7">
<option value="" selected="selected">
---------
</option>
<option>
Male
</option>
<option>
Female
</option>
</select>
</td>
<td>
<input id="phonenumber_row7" name="phonenumber_row7" type="text">
</td>
</tr>发布于 2013-03-14 02:16:35
您需要将tr内的表单元素作为目标- serializeArray不会在仅限tr的表单元素和表单控件上工作
来自jQuery .serializeArray()文档
此方法可以作用于选择了各个表单元素的jQuery对象,如
<input>、<textarea>和<select>。但是,选择<form>标记本身进行序列化通常更容易:
// serialize all form controls with a name attribute
$('#row7 :input[name]').serializeArray();https://stackoverflow.com/questions/15392813
复制相似问题