jquery – 如何在单击表格中的按钮时查找rowindex

栏目: jQuery · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/14112721/how-to-find-rowindex-when-clicked-a-button-in-table

我想找到点击按钮的行.

<table>
  <tr>
    <td>foo 1</td>
    <td><input  type="button" value="Remove" id="remove1"/> </td>
  </tr>
  <tr>
    <td>foo 2 </td>
    <td><input  type="button" value="Remove" id="remove2"/> </td>
  </tr>
</table>

我的表结构如上所述.通常我可以使用buttonid获取行索引.但是如果我删除一行(tr),另一行索引会发生变化.例如:

如果我用jQuery删除第一行,第二行索引更改为0然后我不能使用按钮的id. (删除 – 2)

好吧,我认为我必须使用父功能,但它不起作用.

var elem = $('#remove2');
alert(elem.parent()[0].sectionRowIndex);

我尝试了这个,但没有用.我需要在行中单击按钮的行索引.

我希望我解释了我的问题.

试试这个:
$("table tr input").on('click', function(e){
   alert($(this).closest('td').parent()[0].sectionRowIndex);
});​

FIDDLE

翻译自:https://stackoverflow.com/questions/14112721/how-to-find-rowindex-when-clicked-a-button-in-table


以上所述就是小编给大家介绍的《jquery – 如何在单击表格中的按钮时查找rowindex》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Compilers

Compilers

Alfred V. Aho、Monica S. Lam、Ravi Sethi、Jeffrey D. Ullman / Addison Wesley / 2006-9-10 / USD 186.80

This book provides the foundation for understanding the theory and pracitce of compilers. Revised and updated, it reflects the current state of compilation. Every chapter has been completely revised ......一起来看看 《Compilers》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

html转js在线工具
html转js在线工具

html转js在线工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具