怎样在单元格中的事件中删除行?

zyq_123 2011-01-26 08:52:30
<table>
<tr>
<td>

</td>
<td>
<a href="#" onclick="delrow()">
</td>
</tr>
<tr>
<td>

</td>
<td>
<a href="#" onclick="delrow()">
</td>
</tr>
</table>

<script type="text/javascript">
function delrow(){
//怎样处理可以删除所在行?
}
</script>
...全文
118 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
hch126163 2011-01-27
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 theforever 的回复:]

类似的问题,我记得回答过了。

HTML code
<script>
function delrow(tdContent)
{
var tr=tdContent.parentNode.parentNode;
tr.parentNode.deleteRow(tr.rowIndex);
}
</script>
<table id="table1">
<tr>
<td>甲……
[/Quote]

+1
zyzy15 2011-01-27
  • 打赏
  • 举报
回复
3楼的代码还可以写成这样

function delrow(tdContent){
document.getElementById("tab").deleteRow(tdContent.parentNode.parentNode.rowIndex);
}
打字员 2011-01-27
  • 打赏
  • 举报
回复
这年头,有分才是王道。。。。
仲兴轩 2011-01-27
  • 打赏
  • 举报
回复
楼主真有才,问下删除行的,出这么多帖子?

wan
打字员 2011-01-27
  • 打赏
  • 举报
回复
//通用性,不管tr下有多少层子元素。


function removeTR(obj) {
var s = obj.parentNode;
var st = s.tagName.toLowerCase();
switch(st) {
case 'tr':
s.parentNode.deleteRow(s.rowIndex);
break;
case 'body':
break;
default:
removeTR(s);
}
}
无·法 社区初级成员 T1 2011-01-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhongxingxuan 的回复:]

JQuery更简单:
function delrow(tdContent)
{
$(tdContent).parent().parent().remove();
}
</script>
<table id="table1">
<tr>
<td>甲</td>
<td><a href="#" onclick="delrow(this)">删除</a></td>
</tr>
<tr>
<td>乙</td>
<td><a href="#" onclick="delrow(this)">删除</a></td>
</tr>
</table>
[/Quote]这个貌似很简洁啊,不过效率要求高的话就用原生的吧。
gouxiongyaya 2011-01-27
  • 打赏
  • 举报
回复
顶一下3楼!
pxynet 2011-01-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhongxingxuan 的回复:]

JQuery更简单:
HTML code

<script>
function delrow(tdContent)
{
$(tdContent).parent().parent().remove();
}
</script>
<table id="table1">
<tr>
<td>甲</td>
<td><a href="#" onclick="delrow(this……
[/Quote]
+1
仲兴轩 2011-01-27
  • 打赏
  • 举报
回复
JQuery更简单:

<script>
function delrow(tdContent)
{
$(tdContent).parent().parent().remove();
}
</script>
<table id="table1">
<tr>
<td>甲</td>
<td><a href="#" onclick="delrow(this)">删除</a></td>
</tr>
<tr>
<td>乙</td>
<td><a href="#" onclick="delrow(this)">删除</a></td>
</tr>
</table>


wan
  • 打赏
  • 举报
回复
类似的问题,我记得回答过了。

<script>
function delrow(tdContent)
{
var tr=tdContent.parentNode.parentNode;
tr.parentNode.deleteRow(tr.rowIndex);
}
</script>
<table id="table1">
<tr>
<td>甲</td>
<td><a href="#" onclick="delrow(this)">删除</a></td>
</tr>
<tr>
<td>乙</td>
<td><a href="#" onclick="delrow(this)">删除</a></td>
</tr>
</table>
zyq_123 2011-01-26
  • 打赏
  • 举报
回复
就是点击该行的删除标签,就删除该行。
zyq_123 2011-01-26
  • 打赏
  • 举报
回复
<table>
<tr>
<td>

</td>
<td>
<a href="#" onclick="delrow()">删除</a>
</td>
</tr>
<tr>
<td>

</td>
<td>
<a href="#" onclick="delrow()">删除</a>
</td>
</tr>
</table>

<script type="text/javascript">
function delrow(){
//怎样处理可以删除所在行?
}
</script>

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧