美文网首页
checkbox全选与全不选

checkbox全选与全不选

作者: 給我小鱼干 | 来源:发表于2018-07-30 18:35 被阅读0次
    //全选全不选
        function chooseResource() {
            $('input[name="choseAll"]').change(function() {
                if ($('input[name="choseAll"]').is(':checked')) {
                    $('input[name="choseItem"]').each(function(index, item) {
                        $(item).prop('checked', true);
                    });
                } else {
                    $('input[name="choseItem"]').each(function(index, item) {
                        $(item).prop('checked', false);
                    });
                };
            });
    
    
        }
        //反选
        function isChoseAll() {
            $('input[name="choseItem"]').change(function() {
                try {
                    $('input[name="choseItem"]').each(function(index, item) {
                        if (!$(item).is(':checked')) {
                            $('input[name="choseAll"]').removeAttr('checked');
                            throw "error";
                            return;
                        }
    
                    })
                } catch (e) {
                    return;
                }
                $('input[name="choseAll"]').prop('checked', true);
    
            })
        }
    

    相关文章

      网友评论

          本文标题:checkbox全选与全不选

          本文链接:https://www.haomeiwen.com/subject/bxfqvftx.html