在jQuery中获取表的当前rowIndex [英] Get current rowIndex of table in jQuery

查看:1049
本文介绍了在jQuery中获取表的当前rowIndex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击时,我的表格单元格将突出显示.我需要找到突出显示的单元格的rowIndex. 我尝试过这样做

My table cell gets highlighted when clicked. I need to find the rowIndex of highlighted cell. I tried doing like this

$(".ui-state-highlight").index(); // Results to 0

我也尝试过...

$('td').click(function(){

    var row_index = $(this).parent().index('tr');

    var col_index = $(this).index('tr:eq('+row_index+') td');

    alert('Row # '+(row_index)+' Column # '+(col_index));

}); 
// Results : Row # -1 Column # -1

我通过发布并尝试第一个答案,仍然无法获得结果.

I went to through this post and tried the first answer, still couldn't get the result.

推荐答案

尝试一下,

$('td').click(function(){
   var row_index = $(this).parent().index();
   var col_index = $(this).index();
});

如果需要表包含td的索引,则可以将其更改为

If you need the index of table contain td then you can change it to

var row_index = $(this).parent('table').index(); 

这篇关于在jQuery中获取表的当前rowIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆