当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - get row number on row click in jQuery for bootstrap table

问题描述:

As easy as it sounds but I am stuck in retrieving the row number of the current clicked/selected row.

I have tried the following so far.

I am using bootstrap table just in case you want to know.

$('#myTable').on('click-row.bs.table', function (e, row, $element) {

//var row_num = parseInt($(this).parent().index()) + 1;

//var row_num = $(this).closest('tr').index();

//var row_num = $(this).closest('td').parent()[0].sectionRowIndex;

}

None seem to be working for me.

网友答案:

Th problem you have is simply about the way that click-row.bs.table works, as far as click-row.bs.table is a table event, this keyword points to the table itself not to the row, so you just need to use the $element instead:

$('#myTable').on('click-row.bs.table', function (e, row, $element) {
  var row_num = $element.index() + 1;
});
分享给朋友:
您可能感兴趣的文章:
随机阅读: