我使用数据表 ( http://datatables.net/ ) 使用 JSON 创建表,我有一个代码:
<script type="text/javascript">
$(document).ready(function() {
$('#example').dataTable( {
"ajax": "objects.txt",
"columns": [
{ "data": "name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "extn" },
{ "data": "start_date" },
{ "data": "salary" }
]
} );
} );
</script>
<div class="container">
<table id="example" class="table table-striped table-bordered table-responsitive" cellspacing="0" width="100%">
<thead>
<tr>
<th>DAN</th>
<th>Aktivnost</th>
<th>Vreme</th>
<th>Rashodi</th>
<th>Prihodi</th>
<th>Beleske</th>
</tr>
</thead>
<tfoot>
<tr>
<th>DAN</th>
<th>Aktivnost</th>
<th>Vreme</th>
<th>Rashodi</th>
<th>Prihodi</th>
<th>Beleske</th>
</tr>
</tfoot>
</table>
</div>
单击某个单元格时如何获取行名和列名? 还有如何在单击表格中的某个单元格时获取行 ID 和列 ID?
最佳答案
我认为这对你有帮助:
或
您可以使用 JQuery 尝试这种类型的代码:
$('#example tbody').on( 'click', 'td', function () {
alert('Data:'+$(this).html().trim());
alert('Row:'+$(this).parent().find('td').html().trim());
alert('Column:'+$('#example thead tr th').eq($(this).index()).html().trim());
});
这是 JQuery 代码的 fiddle :CLICK HERE
关于javascript - 单击数据表中的单元格时获取列名和行名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26646597/