jquery删除指定的行

liangphp 2011-07-29 08:48:58
<tr id=\"LcTr1\"><td>hello world</td></tr><a href=\"#\">删除</a>
<tr id=\"LcTr2\"><td>hello world</td></tr><a href=\"#\">删除</a>
<tr id=\"LcTr3\"><td>hello world</td></tr><a href=\"#\">删除</a>
<tr id=\"LcTr4\"><td>hello world</td></tr><a href=\"#\">删除</a>

怎么通过jquery删除啊,请前辈指点指点啊
...全文
463 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
liangphp 2011-07-29
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 pj100 的回复:]
一般情况下,所有编辑是一个样式,所有删除是一个样式,都加上样式就OK了
$(".table .del").click(function(){
$(this).parent().parent().remove();
return false;
});

在删除上面加上class = 'del'
[/Quote]
前辈 我给table加了个id,怎么就不好用了啊

$("#Ptable .del").click(function(){
$(this).parent().parent().remove();
return false;
});
燥动的心 2011-07-29
  • 打赏
  • 举报
回复
一般情况下,所有编辑是一个样式,所有删除是一个样式,都加上样式就OK了
$(".table .del").click(function(){
$(this).parent().parent().remove();
return false;
});

在删除上面加上class = 'del'
liangphp 2011-07-29
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 pj100 的回复:]
HTML code
<table class="table">
<tr id=\"LcTr1\"><td>hello world</td><td><a href=\"#\">删除</a></td></tr>
<tr id=\"LcTr2\"><td>hello world</td><td><a href=\"#\">删除</a></td></tr>
<tr id=\……
[/Quote]

最好是可以通过id删除的啊,通过行的id,啊
liangphp 2011-07-29
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zhongxingxuan 的回复:]
HTML code

<!-- 用table最好有东西就写在TD里面, TD和TR之外最好不要写东西, 要不然会对页面显示有影响 -->
<table class="table">
<tr id=\"LcTr1\"><td>hello world</td><td><a href=\"#\">删除</a></td></tr>
<tr id=\"LcTr2\"><td>hel……
[/Quote]
非常感谢您的帮助,如果我还有一个<a href=\"#\">编辑</a>的标签在表格里,就不能用标签的选择器了啊,可我给<a>标签加上id之后,通过id找,就不好用了啊
燥动的心 2011-07-29
  • 打赏
  • 举报
回复
<table class="table">
<tr id=\"LcTr1\"><td>hello world</td><td><a href=\"#\">删除</a></td></tr>
<tr id=\"LcTr2\"><td>hello world</td><td><a href=\"#\">删除</a></td></tr>
<tr id=\"LcTr3\"><td>hello world</td><td><a href=\"#\">删除</a></td></tr>
<tr id=\"LcTr4\"><td>hello world</td><td><a href=\"#\">删除</a></td></tr>
</table>

<script type="text/javascript">
$(".table a").click(function(){
$(this).parent().parent().remove();
return false;
});
</script>
了無痕 2011-07-29
  • 打赏
  • 举报
回复
<tr id=\"LcTr1\"><td>hello world</td></tr><a href=\"#\">删除</a>
<tr id=\"LcTr2\"><td>hello world</td></tr><a href=\"#\">删除</a>
<tr id=\"LcTr3\"><td>hello world</td></tr><a href=\"#\">删除</a>
<tr id=\"LcTr4\"><td>hello world</td></tr><a href=\"#\">删除</a>

被楼主的格式,忽悠了
-------------------------
2楼的就可以实现楼主想要的
仲兴轩 2011-07-29
  • 打赏
  • 举报
回复

<!-- 用table最好有东西就写在TD里面, TD和TR之外最好不要写东西, 要不然会对页面显示有影响 -->
<table class="table">
<tr id=\"LcTr1\"><td>hello world</td><td><a href=\"#\">删除</a></td></tr>
<tr id=\"LcTr2\"><td>hello world</td><td><a href=\"#\">删除</a></td></tr>
<tr id=\"LcTr3\"><td>hello world</td><td><a href=\"#\">删除</a></td></tr>
<tr id=\"LcTr4\"><td>hello world</td><td><a href=\"#\">删除</a></td></tr>
</table>



$(function(){
$(".table a").each(function(){
$(this).click(function(){
$(this).parent().parent().remove();
});
});
});
了無痕 2011-07-29
  • 打赏
  • 举报
回复
$().ready(function(){
$("a[href=#]").each(function(){
$(this).click(function(){
$(this).prev().remove();
});
});
});
燥动的心 2011-07-29
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 liangphp 的回复:]

不行啊, 我想要的效果就是删除行的条件就是根据行的id来删除,如果根据表格的行删的话,我还有个手动添加就不好用了,它俩好像就冲突了,请前辈再给支个招啊,
[/Quote]
觉得要改的是你的添加功能,而不是删除功能.怎么冲突了,你又不会说清楚.
根据ID来删除,有十行就十个ID吗,那样要判断多少次啊.
MuBeiBei 2011-07-29
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 liangphp 的回复:]
引用 10 楼 liujian650107 的回复:
引用 8 楼 liangphp 的回复:

引用 7 楼 pj100 的回复:
一般情况下,所有编辑是一个样式,所有删除是一个样式,都加上样式就OK了
$(".table .del").click(function(){
$(this).parent().parent().remove();
return false;
});
……
[/Quote]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="http://www.wanmei.com/public/js/jq_132.js"></script>
</head>

<body>
<table class="table">
<tr id="bianji"><td>hello world</td><td><a href="#">编辑</a></td></tr>
<tr id="LcTr1"><td>hello world</td><td><a href="#">删除</a></td></tr>
<tr id="LcTr2"><td>hello world</td><td><a href="#">删除</a></td></tr>
<tr id="LcTr3"><td>hello world</td><td><a href="#">删除</a></td></tr>
<tr id="LcTr4"><td>hello world</td><td><a href="#">删除</a></td></tr>
</table>

<script language="javascript" type="text/javascript">
$(function(){
$(".table a").each(function(){
$(this).click(function(){
var id = $(this).parent().parent().attr('id');
if(id.indexOf('LcTr') == 0){
$(this).parent().parent().remove();
}
});
});
});

</script>

</body>
</html>
liangphp 2011-07-29
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 liujian650107 的回复:]
引用 8 楼 liangphp 的回复:

引用 7 楼 pj100 的回复:
一般情况下,所有编辑是一个样式,所有删除是一个样式,都加上样式就OK了
$(".table .del").click(function(){
$(this).parent().parent().remove();
return false;
});

在删除上面加上class = 'del'

前……
[/Quote]

不行啊, 我想要的效果就是删除行的条件就是根据行的id来删除,如果根据表格的行删的话,我还有个手动添加就不好用了,它俩好像就冲突了,请前辈再给支个招啊,
小辛、 2011-07-29
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 liangphp 的回复:]

引用 7 楼 pj100 的回复:
一般情况下,所有编辑是一个样式,所有删除是一个样式,都加上样式就OK了
$(".table .del").click(function(){
$(this).parent().parent().remove();
return false;
});

在删除上面加上class = 'del'

前辈 我给table加了个id,怎么就不好用了啊……
[/Quote]

我问一下 你给TABLE加上ID之后 你的A标签给del的样式了么?
如果没给加del的样式 在加一下那个样式基本就能解决了吧~
liangphp 2011-07-29
  • 打赏
  • 举报
回复
没有高手给帮忙看看么

87,904

社区成员

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

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