需要在表中选择NEXT行的CSS选择器 [英] CSS selector needed to select the NEXT row in a table

查看:157
本文介绍了需要在表中选择NEXT行的CSS选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我简化了如下所示的情况:

I have simplified the situation as shown below:

 <table>
  ...
  <tr><td>....</td><td><button...>delete</button></td></tr>
  <tr><td>somestuff</td><td>some other stuff</td></tr>

 </table>

单击删除按钮后,我使用以下方法删除行:

On click of the delete button, I delete the row by using:

  $(this).closest('tr').remove();

我的问题是,我如何也使用下一行的CSS选择器删除下一行. 我有一种解决方法,即为每行使用一个运行的ID号,选择已删除ID的ID#,对其进行递增,然后使用它来删除下一行,但是我认为必须有一些CSS选择器才能选择下一行行.

My question is, how do I delete the next row too using some CSS selector for the next row. I have a work-around by using a running id number for each row, picking the id # of the one deleted, incrementing it and then using it to delete the next row, but I think there must be some CSS selector to select the next row.

推荐答案

您最好的选择是分开查找行并将其删除-否则您将得到无法预测的结果.

Your best bet is to separate finding the rows, and removing them - otherwise you'll get unpredictable results.

var rowA = $(this).closest('tr');
var rowB = rowA.next();

rowA.remove();
rowB.remove();

这篇关于需要在表中选择NEXT行的CSS选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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