JQuery对Table进行全选反选 增加节点 删除节点

<!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>
    <style type="text/css">
      table
     {
         width:600px;
         height:300px;
     }
    </style>
    <script src="Jquery1.7.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            //        全选
            $('#CkcAll').click(function () {
                $('table input[type=checkbox]').attr('checked', $(this).is(':checked'));
                if (this.checked) {
                    $('#s1').text('取消全选');
                }
                else {
                    $('#s1').text('全选');
                }
            })
            //            反选
            $('#CkcFan').click(function () {
                $('table input[type=checkbox]').each(function () {
                    if (this.checked) {
                        $(this).attr('checked', false);
                    }
                    else {
                        $(this).attr('checked', true);
                    }

                })
            })

            $('#btdelete').click(function () {
                $('table input:checked').each(function () {
                    $(this).parent().parent().remove();
                })
            })
            $('#BtnAdd').click(function () {
                var txt1 = $("#Text1").val();
                var txt2 = $("#Text2").val();
                var txt3 = $("#Text3").val();
                var txt4 = $("#Text4").val();
                var txt5 = $("#Text5").val();
                var str = '<tr><td><input type="checkbox" /></td><td>' + txt1 + '</td><td>' + txt2 + '</td><td>' + txt3 + '</td><td>' + txt4 + '</td><td>' + txt5 + '</td></tr>';
                $('table').append(str);
            });
        })
    </script>
</head>
<body>
    <div><input id="CkcAll" type="checkbox" /><span id="s1">全选</span><input id="CkcFan" type="checkbox" />反选<input
            id="btdelete" type="button" value="删除" /></div>
 <table id="t1">
  <tr>
     <td>操作</td>
     <td>班级</td>
     <td>姓名</td>
     <td>薪水</td>
     <td>就业单位</td>
     <td>是否转正</td>
  </tr>
  <tr>
    <td>
        <input id="Checkbox1" type="checkbox" /></td>
    <td>11Net</td>
    <td>刘晓飞</td>
    <td>4000</td>
    <td>CSDN</td>
    <td>是</td>
  </tr>
  <tr>
   <td>
        <input id="Checkbox2" type="checkbox" /></td>
    <td>11Net</td>
    <td>张东</td>
    <td>4000</td>
    <td>微软</td>
    <td>否</td>
  </tr>
  <tr>
   <td>
        <input id="Checkbox3" type="checkbox" /></td>
   <td>11Net</td>
   <td>齐志超</td>
   <td>3500</td>
   <td>华为</td>
   <td>是</td>
  </tr>
 </table>
 <br />
    <input id="Text1" type="text" /><br /><br />
    <input id="Text2" type="text" /><br /><br />
    <input id="Text3" type="text" /><br /><br />
    <input id="Text4" type="text" /><br /><br />
    <input id="Text5" type="text" /><br /><br />
    <input id="BtnAdd" type="button" value="添加节点" />

</body>
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值