简体   繁体   中英

Unchecked checkbox when check all checkboxs bootstrap

I have the next HTML code:

          <div class="form-group">
              <div class="col-sm-12 divider">
                <br><label><input type="checkbox" class="checkbox selectAll" value="">Select All</label>
              </div>
          </div>
          <div class="form-group">
              <div class="col-sm-12 ">
                <label><input type="checkbox" class="checkbox" value="">CHS Informed Consent Form</label>
              </div>
              <hr/>
              <div class="col-sm-12">
                <label><input type="checkbox" class="checkbox" value="">Order Sets</label>
              </div>
              <div class="col-sm-12">
                <label><input type="checkbox" class="checkbox" value="">Carboplatin Teaching Sheet</label>
              </div>
              <div class="col-sm-12">
                <label><input type="checkbox" class="checkbox" value="">Bevacizumab Teaching Sheet</label>
              </div>
              <div class="col-sm-12">
                <label><input type="checkbox" class="checkbox" value="">CHS Specialty Pharmacy Sheet</label>
              </div>
              <div class="col-sm-12">
                <label><input type="checkbox" class="checkbox" value="">Calendar</label>
              </div>
              <div class="col-sm-12">
                <label><input type="checkbox" class="checkbox" value="">Healthcare Provider Contact Form</label>
              </div>
          </div>
          <div class="form-group">
              <div class="col-sm-12">
              <button type="submit" class="btn btn-default submit">Generate Super Pack</button>
            </div>
          </div>

        </form>

And the next jquery code:

This toggle the styles

$('.checkbox').checkbox({
    buttonStyle: 'btn-link',
    buttonStyleChecked: 'btn-inverse',
    uncheckedClass: 'icon-check-empty',
    checkedClass: 'btn-inverse'
});

If I want to check all boxes I use:

$(".selectAll").click(function () {
    $('input:checkbox').not(this).prop('checked', this.checked);
});

But my problem is, when I have one or more item selected and then I choose select All the checked items go unchecked. I'm using bootstrap-checkbox.js
But I can not figure out how solve the problem.

Any idea?

Thank you.

You can use checkbox options to enable/disable them all

$('input:checkbox').not(this).checkbox({checked: this.checked});

http://jsfiddle.net/D2RLR/7108/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM