请看 小提琴。当我点击单元格时,我可以获得值和列名。我想知道如何获取行和列索引?以下是js代码,
<script type="text/javascript">
$(document).ready(function(){
$('#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());
});
});
</script>
原文由 WCMC 发布,翻译遵循 CC BY-SA 4.0 许可协议
最好的可能是在这里使用
closest
: