【发布时间】:2015-09-27 14:37:14
【问题描述】:
这可能是一个微不足道的问题,但我有点困惑如何提取列数据并构造一个对象。
表格本质上是动态的,根据提供的数据生成。
格式是这样的
<tr>
<td> Label </td>
<td>
<input type = "radio" value="yes"/> YES
<input type = "radio" value="no"/> NO
<textarea>
</td>
<td>
<input type = "radio" value="yes"/> YES
<input type = "radio" value="no"/> NO
<textarea>
</td>
// This structure can repeat
...
...
</tr>
// Rows will repeat themselves
到目前为止,我已经记下了这个
$(function () {
$('#submit').click(function () {
var i = 0;
var t = document.getElementById('table');
$("#table tr").each(function () {
var columns = $(this).find('td');
/* how to extract column data here?, so that I construct
a column object and keep looping for the other columns
});
});
我的 JSON 需要是这样的: [{label:data, isPresent:data, value:data}, {..}, {..}]
我无法一次性获取两列 () 的数据,然后循环遍历接下来的 2 列。
【问题讨论】:
标签: javascript jquery dom