简体   繁体   English

如何根据该行中的单元格获取行索引 javascript

[英]how to get row index based on a cell in that row javascript

So basically my php file will return an echo (as a table), and in that table, each row will have a cell that is a delete button to delete that row.所以基本上我的 php 文件会返回一个回声(作为一个表格),在那个表格中,每一行都会有一个单元格,它是一个删除按钮来删除该行。 whatI want is when button clicked, the row will be delete from table.我想要的是单击按钮时,该行将从表中删除。 So I guess the row index is important to implement this.所以我想行索引对于实现这一点很重要。 But how can I get row index in this situation in javascript?但是在这种情况下,如何在 javascript 中获取行索引?

DOM table element has the method deleteRow and you can get the row index of a table row using rowIndex attribute. DOM 表元素具有deleteRow方法,您可以使用rowIndex属性获取表行的行索引。

var myTable = ...
var rowIndex = btn.parentNode.parentNode.rowIndex;
myTable.deleteRow(rowIndex);`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM