jquery实现checkbox全选/反选/取消

Title 全选(name=ch_all) 反选(name=reverse_all) 取消所有(name=cancle_all)
IP port domain action
1.1.1.1 90 1.bai.com (name=ch)
1.1.1.2 92 2.bai.com
1.1.1.3 93 3.bai.com
1.1.1.4 94 4.bai.com

全选

$('input[name=ch_all]').change(function () {
            if($('input[name=ch_all]').is(':checked')){
                $('input[name=ch]').each(function () {
                $(this).prop('checked', true);
             });
            }else{
                $('input[name=ch]').each(function () {
                $(this).prop('checked', false);
             });
            };
        });

反选

$('input[name=reverse_all]').click(function () {
           $('input[name=ch]').each(function () {
              $(this).prop('checked', !$(this).prop('checked'));
           });
        });

取消

$('input[name=cancle_all]').click(function () {
            $('input[name=ch]').prop('checked', false);
        });
posted @ 2018-11-12 17:03  没脚的丛林鸟  阅读(148)  评论(0编辑  收藏  举报