使用jQuery在单击时隐藏当前表行 [英] Hide current table row on click using jQuery

查看:110
本文介绍了使用jQuery在单击时隐藏当前表行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆表行,例如:

<tr>
  <td>cell1</td>
  <td>cell2</td>
  <td><a href="action.php">cell3</a></td>
</tr>

当有人点击cell3中的链接有没有办法隐藏整个tr行?那么第二个他们点击了cell3中的那个链接整个tr是隐藏的吗?

When someone clicks the link in cell3 is there a way to hide the whole tr row? So the second they click that link in cell3 the whole tr is hidden?

推荐答案

这是 .delegate() ,如下所示:

This is a good place for .delegate(), like this:

$("#tableID").delegate("td:nth-child(3)", "click", function() {
  $(this).closest("tr").hide();
});

使用 .delegate() 我们将一个 点击处理程序附加到<$所有这些第三列单元格的c $ c>< table> ,然后使用 .closest() 爬上< tr> .hide() 。如果你想要它在链接上,只需将 td:nth-​​child(3)更改为 td a ,休息是一样的。

By using .delegate() we attach one click handler to the <table> for all those third-column cells, and then use .closest() to climb up to the <tr> to .hide(). If you want it on the link instead, just change td:nth-child(3) to td a, the rest is the same.

这篇关于使用jQuery在单击时隐藏当前表行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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