使用jquery我需要从表格单元格中检索数组,格式化数据并将其传递给js函数。从表格单元格中获取值并将其转换为数组
我使用的代码是这样的:
var l1 = new Array();
$('table#datatable tbody td:first-child').each(function() {
l1.push($(this).text());
});
这是表片段
<tr>
<th scope="row">Age: 0-4</th>
<td>0</td>
<td>9.7</td>
</tr>
<tr>
<th scope="row">5-17</th>
<td>23.6</td>
<td>18.0</td>
</tr>
<tr>
<th scope="row">Total 0-17</th>
<td>20.6</td>
<td>16.1</td>
</tr>
表的ID是 “数据表”。我想返回的每首个TD的内容数组,然后格式化它是这样的: 0,23.6,20.6
我很新的使用数组...
DOH,我没有意识到,TH算作集的一部分。这工作非常好,谢谢。我正在尝试为jqPlot创建一个将表格转换为图表的插件。 – liz 2010-04-10 18:02:40
@liz - 我以为我认识到这个标记,很高兴这成功了你。对问题进行+1,完全按照它的要求进行提问:包括您尝试的结果和预期结果,标记/代码是一个巨大的优势,使问题更容易回答。 – 2010-04-10 18:05:26
感谢:-)慢慢学习... – liz 2010-04-10 18:19:40