如何从jQuery中的表中删除当前行? [英] How to remove current row from table in jQuery?

查看:92
本文介绍了如何从jQuery中的表中删除当前行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < table> 
< tbody>
< tr>
< td>测试内容< / td>
< td>< input type =buttononClick =remove()>< / td>
< / tr>
....
...

< / tbody>
< / table>

现在如果相同的模式继续,我想删除一行,如果删除按钮被点击行。

解决方案

更好:



<$ 。p $ p> $(本).closest( 'TR')除去();

更多关于最接近的()

 < input type =buttononClick =$(this).closest('tr')。remove();> 

无论您的HTML在单元格中看起来如何,都可以使用该工具。 / strong>


I have a table in html as follows

<table>
<tbody>
<tr>
<td>test content</td>
<td><input type="button" onClick="remove()"></td>
</tr>
....
...

</tbody>
</table>

now if the same pattern continues, i want to remove a row if a remove button is clicked on that row. how do i achieve the same with jQuery?

解决方案

Nicer:

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

More on closest()

<input type="button" onClick="$(this).closest('tr').remove();">

This has the benefit of working no matter what your HTML looks like in the cell.

这篇关于如何从jQuery中的表中删除当前行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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