本文介绍了删除父容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,里面有表格单元格中的字段.在每行的最后一列,我有一张图像.单击该图像时,我要删除父<tr>.在尝试通过生成将行号onclick='delete_row(x, y)'作为参数传递的函数来进行此操作之前.这显然不是一个好的解决方案,因为我按行的位置删除了行.我正在调用的函数还有其他2个参数,因为它也会删除数据库中的行,因此第二个参数是要删除的数据库中的ID.因此,基本上,我需要一个删除父<tr>并接受其他一些参数的函数.

I have a form with the fields inside table cells. On the last column of each line I have an image. When clicking that image I want to delete the parent <tr>. Before I tried to do it by generating a function passing as the argument the line number: onclick='delete_row(x, y)'. This is obviously not a good solution since I was deleting the row by its position. The function I'm calling has other 2 arguments since it deletes the row in the database too, so the second argument is the id in the database to delete. So basically I need a function that deletes the parent <tr> and that accept some other arguments too.

编辑谢谢:谢谢大家,我几乎尝试了所有解决方案,并且效果很好.我刚刚决定为Mike的Samuel设计一个,这似乎是最简单的方法:)再次感谢

EDIT Thanks:Thank you all guys, I tried almost all the solutions and all worked nice. I just decided for the Mike's Samuel one, it seemed the easiest :) Thanks again

推荐答案

要传递当前节点的祖父母,请使用this.parentNode.parentNode:

To pass the grandparent of the current node use this.parentNode.parentNode:

<tr><td><img onclick="delete_row(this.parentNode.parentNode, ...)"></td></tr>

这篇关于删除父容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 02:55