Jquery-1实现简单的复选框删除增加操作

1.实现简单的复选框删除增加操作

<pre name="code" class="html"><!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>简单的复选框删除增加操作</title>
/<span style="font-size:18px;color:#ff0000;">/引用的是jquery-2.2.4.js版本
    <script src="js/jquery-2.2.4.js"></script></span>
    <script>
        $(function(){
           $("input[type=checkbox]:eq(0)").change(function(){
              var checkvalue=$(this).prop("checked");
               <span style="font-size:24px;color:#ff0000;">//not(0)表示不选第一行操作栏</span>
               $("input[type=checkbox]:not(0)").prop("checked",checkvalue);
                if($(this).prop("checked")){
                    $("input[type=checkbox]:not(0)").prop("checked","true");
                }else{
                    $("input[type=checkbox]:not(0)").prop("checked","");
                }
           });
            //单条删除
            $("td a").click(function(){
                //提示框
               if(confirm("你确定真的要删除嘛")){
                   $(this).parent("td").parent("tr").remove();
               }
            });
            //选择框选定的才删除
            $("input[value='删除']").click(function(){
                //提示框
                if(confirm("你确定真的要删除嘛")) {
                    $("input[type='checkbox']:not(:first):checked").parent("td").parent("tr").remove();
                }
            });
            $("input[value='增加']").click(function(){
                //进行字符串拼接
                var strShopInfo="<tr>"+
                "<td><input type=\"checkbox\"/></td>"+
                "<td>张四</td>"+
                "<td>1222211111</td>"+
                "<td><a href=\"#\" οnclick='deleteItem(this)'>删除</a></td>"+
                "</tr>";
                $("#myTableProduct tbody").append(strShopInfo);
            });

        });
        <span style="font-size:32px;color:#ff0000;">//新定义一个方法以便让增加后数据也能删除,关键点</span>
        function deleteItem(obj){
            //提示框
            if(confirm("确定要删除嘛")) {
                $(obj).parent("td").parent("tr").remove();
            }
        }
    </script>
</head>
<body>
<table border="1px" cellspacing="0px" id="myTableProduct">
    <tr>
        <td><input type="checkbox" />全选</td>
        <td>用户名</td>
        <td>电话号码</td>
        <td>操作</td>
    </tr>
    <tr>
        <td><input type="checkbox"/></td>
        <td>张三</td>
        <td>1222211111</td>
        <td><a href="#">删除</a></td>
    </tr>
    <tr>
        <td><input type="checkbox"/></td>
        <td>张四</td>
        <td>1222211111</td>
        <td><a href="#">删除</a></td>
    </tr>
    <tr>
        <td><input type="checkbox"/></td>
        <td>张五</td>
        <td>1222211111</td>
        <td><a href="#">删除</a></td>
    </tr>
</table>
<input type="button" value="增加"/>
<input type="button" value="删除"/>
</body>
</html>

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值