Javascript 单击datatables中的单元格时获取列和行名称

Javascript 单击datatables中的单元格时获取列和行名称,javascript,jquery,datatable,Javascript,Jquery,Datatable,我使用datatables()创建带有JSON的表,我有一个代码: <script type="text/javascript"> $(document).ready(function() { $('#example').dataTable( { "ajax": "objects.txt", "columns": [ { "data": "name" }, { "data": "position"

我使用datatables()创建带有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>

$(文档).ready(函数(){
$('#示例')。数据表({
“ajax”:“objects.txt”,
“栏目”:[
{“数据”:“名称”},
{“数据”:“位置”},
{“数据”:“办公室”},
{“数据”:“extn”},
{“数据”:“开始日期”},
{“数据”:“工资”}
]
} );
} );
丹
阿基维诺斯特
弗里姆
拉肖迪
普里霍迪
贝尔斯克
丹
阿基维诺斯特
弗里姆
拉肖迪
普里霍迪
贝尔斯克
当我单击某个单元格时,如何获取行名称和列名称?
另外,当单击表中的某个单元格时,如何获取行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代码的提琴:

谢谢,这对我有帮助。这里还有其他方法吗?您应该通过
table.row(this.data()
而不是准备HTML DOM来获取行数据