Bootstraps ICheck-Helper does not trigger on chang

2020-02-26 05:35发布

I have this Jquery code to be updating checkboxes base on whether a checkbox has been checked. However, This does not fire.

Code

$('body').on('change', '.territory', function () {
    var PK = $(this).find('input:checkbox:first').val();
    var PKStr = '.parent' + PK;
    console.log('change!');
});

$('body').on('change', '.iCheck-helper', function () {
    //var PK = $(this).find('input:checkbox:first').val();
    //var PKStr = '.parent' + PK;
    console.log('change!');
});

<div class="row">
  <div class="col-md-12 col-lg-12">
    <label class="control-label">
      Selected Territories
    </label>
  </div>

  @for (int c = 0; c < 2; ++c)
  {
     int Count = 0; 
     <div class="col-md-6 col-lg-6">
     @foreach (var ter in Infobase.MMS.Models.ComboBoxValues.GetTerritoryRights(0))
     {
        if (Count % 2 == c)
        {
          <label>
            <input type="checkbox" class="territory" value="@ter.Key">
                                                        &nbsp;@ter.Value

          </label>
        }
        Count++;
      }
   </div>
  }    
</div>

I've tried binding to the click function and change function on iCheckbox-Helper as well as directly to the checkboxes. However neither seem to work. Everything does work fine when I dont add in the Icheck.js script.

Does anybody know how to hook into on changed event from bootstraps Icheckhelper class?

3条回答
你好瞎i
2楼-- · 2020-02-26 06:18

I just added this globally and it does the trick for me.

$(".i-checks input").on('ifChanged', function (e) {
    $(this).trigger("change", e);
});
查看更多
该账号已被封号
3楼-- · 2020-02-26 06:34

Add the jQuery Events the trigger the onClick Event

$('input[type="checkbox"], input[type="radio"]').on('ifChanged', function (e) {
     $(this).trigger("onclick", e);
});
查看更多
地球回转人心会变
4楼-- · 2020-02-26 06:35

Use ifChanged or ifChecked mentioned in the documentation

$('input').on('ifChecked', function(event){
  alert(event.type + ' callback');
});
查看更多
登录 后发表回答