ddxiami

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2999|回复: 0

[Jquery] Jquery新增或删除表格文本框

[复制链接]
发表于 2016-2-4 13:33:33 | 显示全部楼层 |阅读模式
<!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>
<title>新增或删除表格文本框</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    /*添加行数据*/
    $(".J_add").click(function(){
        var this_html=$(this).parents("tr").html();//当前新增所在行的html
        var after_tr=$(this).parents("tr").after("<tr class='after_tr'></tr>");//向当前行插入一行tr
        var after_tr=$(".after_tr");//选择插入行的类名
        after_tr.html(this_html);//把变量this_html内容插入到创建后的空tr中
        after_tr.find(".J_add").addClass("J_del").removeClass("J_add").text("删除");//把原来新增操作改成删除操作,并且把它的类名改成J_del
    });
    //移除方法
    $(".J_del").live("click",function(){
        $(this).parents("tr").remove();
    });
})
</script>
</head>
<body>
<table>
  <thead><tr><td>SKU</td><td>赠送数量</td><td>单价</td><td>总价</td><td>操作</td></tr></thead>
  <tbody>
    <tr><td><input type="text" name="ssd"></td><td><input type="text"></td><td>$44</td><td>$22</td><td><a class="J_add">新增</a></td></tr>
  </tbody>
</table>
</body>
</html>

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|技术文档库 ( 闽ICP备15017263号-2 )|网站地图

GMT+8, 2025-5-19 00:38 , Processed in 0.038515 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表