ajax+jqery 批量删除

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    <script src='http://code.jquery.com/jquery-2.1.1.min.js'></script>

</head>

<body>

    <!-- <div class="modal fade" id="updateModel" role="dialog">

        这是什么!!!!

    </div> -->

    <div>

        <div>

            姓名:<input type="text" name="uname" id="">

            年龄:<input type="text" name="uage" id="">

            地址:<input type="text" name="uaddr" id="">

            <input type="button" value="添加" name="add">

            <input type="button" value="批量删除" name="rmrf">

        </div>

        <div>

            <table border="1px" cellspacing="0" cellpadding="1">

               <thead>

                    <tr>

                        <th>

                            <input type="checkbox" name="" id="" οnchange="checkAll(this)">

                        </th>

                        <th>姓名</th>

                        <th>年龄</th>

                        <th>地址</th>

                        <th>操作</th>

                    </tr>

                </thead>

                <tbody>

                    <tr>

                        <td><input type="checkbox" name="" id=""></td>

                        <td>骨王</td>

                        <td>19</td>

                        <td>大坟墓</td>

                        <td>

                            <input type="button" value="修改" οnclick="update(this)" class = ".xg">

                            <input type="button" value="删除" οnclick="del(this)">

                        </td>

                    </tr>

                </tbody>

            </table>

        </div>

    <script>

        $(function () {

            $("input[name='add']").click(function () {

               // console.log($(this));

                //获取input内容

                var uname = $("input[name='uname']").val();

                var uage = $("input[name='uage']").val();

                var uaddr = $("input[name='uaddr']").val();

                //表格追加 把input的值放入trDom     让表格追加三个值

                var trDom = $("<tr>" +

                    "<td><input type='checkbox' name='' id='' ></td>" +

                    "<td>" + uname + "</td>" +

                    "<td>" + uage + "</td>" +

                    "<td>" + uaddr + "</td>" +

                    "<td>" +

                    "<input type='button' value='修改' class='modify' οnclick='update(this)'>" +

                    "<input type='button' value='删除' οnclick='del(this)'>" +

                    " </td>" +

                    "</tr>");

               

                $("table tbody").append(trDom);

            })

            $("input[name='rmrf']").click(function () {

                console.log($(this));

                var checedkBoxDom = $("tbody [type='checkbox']:checked  ")

                console.log(checedkBoxDom)

                $.each(checedkBoxDom, function (index, value) {

                    $(this).parent().parent().remove();

                })

            }

            )

            console.log($(this));

        })

        function update(thisDom) {

                console.log($(thisDom));

                var uname = $("input[name='uname']").val();

                var uage = $("input[name='uage']").val();

                var uaddr = $("input[name='uaddr']").val();

            //    if(){

            //    }

            //修改失败1

            $(".modify").click(function () {

                $(this).parent().siblings("td").each(function () {

                    var a = $(this).find("input text");

                    if (!a.length) {

                        $(this).html("<input size='13' type='text' value='" + $(this).text() + "'/>");

                    } else {

                        $(this).html(a.val()).replaceWith(("<tb>Paragraph. </tb>"))

                    }

                    

                })

            })

        }

        function del(thisDom) {

            //    $(tdisDom).parent().parent().empty()

            $(thisDom).parent().parent().empty()

        }

        //全选

        function checkAll(thisDom) {

            //console.log( $(thisDom).prop('checked',true));

            var checkBoxDom = $("tbody [type='checkbox']")

            console.log(checkBoxDom)

            $.each(checkBoxDom, function (index, value) {

                $(this).prop('checked', !$(this).prop('checked'))

            })

        }

    </script>

</body>

</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值