使用jQuery查找表行索引 [英] Find Table Row Index using jQuery

查看:136
本文介绍了使用jQuery查找表行索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是jQuery的中间用户。我知道使用jquery找到表的rowIndex,但我的场景是另一个。我的表(GridView)由20列组成,每列包含不同的控件,如文本框,下拉列表,图像,标签。所有都是每行中的服务器端控件。我将gridview与数据库中的记录绑定在一起。现在当我点击任何控件或任何文本框的更改时,我需要获取该更改列的行的rowIndex。以下是我用户的代码:

I'm an intermediate user in jQuery. I know to find the rowIndex of a table using jQUery, but my scenario is a different one. My table(GridView) consists of 20 columns and each column with different controls like textbox, dropdownlist, image, label. All are server side controls in each row. I bind the gridview with the records from the database. Now when I click on any control or onchange of any textbox, I need to get the rowIndex of that changed column's row. Here is the code I've user:

$("#gv1 tr input[name $= 'txtName']").live('click', function(e){
   alert($(this).closest('td').parent().attr('sectionRowIndex'));
});

但我无法获得rowIndex。如果我在gridview中使用任何html控件,我就能得到rowIndex。当点击gridview中的服务器控件时,有没有办法找出rowIndex?

But I'm unable to get the rowIndex. If I use any html control inside the gridview, I'm able to get the rowIndex. Is there any way to find out the rowIndex when a server control inside the gridview is clicked?

推荐答案

试试这个:

var rowIndex = $(this)
    .closest('tr') // Get the closest tr parent element
    .prevAll() // Find all sibling elements in front of it
    .length; // Get their count

这篇关于使用jQuery查找表行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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