jquery点击事件获取table行号、列号

来源:互联网 发布:淘宝上怎么买处方药 编辑:程序博客网 时间:2024/05/29 16:38
tabel点击行,获取行号
$('#table tbody').on( 'click', 'tr', function (e) {
var index = $(this).parent().context._DT_RowIndex; //行号
var rows = table.rows( index ).data();//获取行数据

});

tabel点击td,获取行号和列号
$('#table tbody').on( 'click', 'td', function (e) {
var cellindex = $(this).parent().context._DT_CellIndex.column; //列号
var rowindex = $(this).parent().context._DT_CellIndex.row; //行号

或者如下
var tdSeq = $(this).parent().find("td").index($(this)[0]); //列号
var trSeq = $(this).parent().parent().find("tr").index($(this).parent()[0]); //行号
});

table点击td中的a标签或者td中的其他标签,获取行号和列号
$('#table tbody').on( 'click', 'a', function (e) {
var cellindex = $(this).parent()[0]._DT_CellIndex.column; //列号
var rowindex = $(this).parent()[0]._DT_CellIndex.row; //行号
});

1 1