Jam*_* D. 5 javascript datatable jquery
我使用datatables(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>
Run Code Online (Sandbox Code Playgroud)
当我点击某个单元格时,如何获取行的名称和列的名称?另外,当点击表格中的某个单元格时,如何获取行的ID和列的ID?
Jar*_*ark 12
我想这会对你有所帮助:
要么
您可以使用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());
});
Run Code Online (Sandbox Code Playgroud)
这是JQuery代码的小提琴:点击这里
归档时间: |
|
查看次数: |
22395 次 |
最近记录: |