如何用jquery来实现添加删除表格?

xyflash2 2011-06-01 03:58:09
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody id="ob">
<tr>
<td valign="top">AAAA<input type="button" name="add" id="add" value="添加" />
  
<input type="button" name="del" id="del" value="删除" />
</td>
</tr>
</tbody>
<tbody id="nb"></tbody>
</table>


点击添加 则将ob中的内容复制到nb中 点击删除则 对应在nb中做删除操作!

如何用jquery来实现?
...全文
110 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xyflash2 2011-06-04
  • 打赏
  • 举报
回复
关注!!!!!!!!!!!!!!!
xyflash2 2011-06-02
  • 打赏
  • 举报
回复
需要的是:点击删除 只删除“删除”按钮所在行
xyflash2 2011-06-01
  • 打赏
  • 举报
回复
需要的是:点击删除 只删除“删除”按钮所在行
zhangxiaoyan06 2011-06-01
  • 打赏
  • 举报
回复

<!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=gb2312" />
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<title>无标题文档</title>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("input[name='add']").click(function(){
$("#nb").append($("#ob").html());
});
$("input[name='del']").click(function(){
//$("#nb").empty(); //全部删除
$("#nb").children("tr:last").remove();//删除最新添加的
});
});

</script>
</head>

<body>
<table width="100%" border="5" cellspacing="0" cellpadding="0" style=" border-color:#F00">
<tbody id="ob" >
<tr>
<td valign="top">AAAA<input type="button" name="add" value="添加" />
  
<input type="button" name="del" value="删除" />
</td>
</tr>
</tbody>
<tbody id="nb"></tbody>
</table>
</body>
</html>

zhangxiaoyan06 2011-06-01
  • 打赏
  • 举报
回复

$(document).ready(function(){
$("input[name='add']").click(function(){
$("#nb").append($("#ob").html());
});
$("input[name='del']").click(function(){
//$("#nb").empty(); //全部删除
$("#nb").children("tr:last").remove();//删除最新添加的
});
});
ypb137154098 2011-06-01
  • 打赏
  • 举报
回复


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script src="jquery-1.4.4.min.js"></script>
</head>
<script type="text/javascript">
<!--
function add(){
var content = $("#ob").html();
$("#nb").append(content);
}

function remove(){
$("#nb").html("");
}
//-->
</script>
<body>
<table width="100%" border="1" cellspacing="0" cellpadding="0" >
<tbody id="ob">
<tr>
<td valign="top">AAAA</td>
<td>
<input type="button" name="add" id="add" value="添加" onclick="add()" />
  
<input type="button" name="del" id="del" value="删除" onclick="remove()"/>
</td>
</tr>
</tbody>
<tbody id="nb"></tbody>
</table>

</body>
</html>


87,904

社区成员

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

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