现在,我有以下的HTML表:数据表:从DOM数据源通过名称引用列
<table id="datatable">
<thead>
<th>fruits</th>
<th>vegs</th>
</thead>
<tbody>
<tr>
<td>apple</td>
<td>potato</td>
</tr>
<tr>
<td>apple</td>
<td>carrot</td>
</tr>
</tbody>
</table>
而且我想通过名称来引用的列是这样的:
<script type="text/javascript">
$(document).ready(function() {
/* Init the table */
var oTable = $('#datatable').dataTable();
//get by sTitle
console.log(oTable);
var row = oTable.fnGetData(1)
console.log(row['vegs']);//should return 'carrot'
});
</script>
无论如何有一个JavaScript函数fnGetData()
返回一个对象,而不是数组,当数据源是DOM?
棘手。如果您有两个具有相同类/文本值的标题单元格,会发生什么情况? – Bergi
嗯...我不确定,但我想它会返回第一个。 –