【发布时间】:2014-04-05 19:17:36
【问题描述】:
我有一张如下所示的表格。
有没有一种方法可以搜索表格以查找某个项目(列 Cat)的所有出现,然后将下一列(列 Vol)中的值添加到数组中,如下例所示 + 显示 0 如果它没有出现在一列中?
注意:每个值在一列中只能出现一次。
我的桌子:
<table id="myTable">
<thead>
<tr>
<th class="myHeader">Cat 1</th>
<th>Vol 1</th>
<th class="myHeader">Cat 2</th>
<th>Vol 2</th>
<th class="myHeader">Cat 3</th>
<th>Vol 3</th>
//...
</tr>
</thead>
<tbody>
<tr>
<td>item1</td><td>8</td><td>item2</td><td>7</td>
</tr>
<tr>
<td>item3</td><td>5</td><td>item2</td><td>7</td>
</tr>
<tr>
<td>item2</td><td>1</td><td>item1</td><td>5</td><td>item3</td><td>3</td>
</tr>
//...
</tbody>
</table>
要求的结果:
var x = [8, 0, 5] // example outcome when searching for "item1"
var y = [7, 7, 1] // example outcome when searching for "item2"
var z = [0, 5, 3] // example outcome when searching for "item3"
非常感谢您提供的任何帮助,蒂姆。
【问题讨论】:
标签: jquery arrays loops for-loop find