内容简介:翻译自: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);
});
翻译自:https://stackoverflow.com/questions/14112721/how-to-find-rowindex-when-clicked-a-button-in-table
以上所述就是小编给大家介绍的《jquery – 如何在单击表格中的按钮时查找rowindex》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 通过按钮单击保存PhpSpreadSheet
- Flex中如何判断是否在组件之外单击
- 担心自己是否中了勒索病毒?单击这里自行查询
- ML.NET 1.0 发布,单击右键即可添加机器学习模型
- angularjs – 量角器按钮在新选项卡中单击并打开页面
- c# – 如果单击保存文件对话框上的取消按钮,如何执行某些操作?
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Smashing Book
Jacob Gube、Dmitry Fadeev、Chris Spooner、Darius A Monsef IV、Alessandro Cattaneo、Steven Snell、David Leggett、Andrew Maier、Kayla Knight、Yves Peters、René Schmidt、Smashing Magazine editorial team、Vitaly Friedman、Sven Lennartz / 2009 / $ 29.90 / € 23.90
The Smashing Book is a printed book about best practices in modern Web design. The book shares technical tips and best practices on coding, usability and optimization and explores how to create succes......一起来看看 《The Smashing Book》 这本书的介绍吧!