jQuery Bootstraps ICheck-Helper 不会在更改事件时触发
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24682126/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstraps ICheck-Helper does not trigger on changed event
提问by johnny 5
I have this Jquery code to be updating checkboxes base on whether a checkbox has been checked. However, This does not fire.
我有这个 Jquery 代码要根据复选框是否被选中来更新复选框。但是,这不会触发。
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">
@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.
我已经尝试绑定到 iCheckbox-Helper 上的单击功能和更改功能以及直接绑定到复选框。然而,两者似乎都不起作用。当我不添加 Icheck.js 脚本时,一切正常。
Does anybody know how to hook into on changed event from bootstraps Icheckhelper class?
有人知道如何从引导程序 Icheckhelper 类中挂钩更改的事件吗?
回答by chris
Use ifChanged or ifChecked mentioned in the documentation
使用文档中提到的 ifChanged 或 ifChecked
$('input').on('ifChecked', function(event){
alert(event.type + ' callback');
});
回答by Beakie
I just added this globally and it does the trick for me.
我刚刚在全球范围内添加了这个,它对我有用。
$(".i-checks input").on('ifChanged', function (e) {
$(this).trigger("change", e);
});
回答by Bharat Kumar
Add the jQuery Events the trigger the onClick Event
添加 jQuery 事件触发 onClick 事件
$('input[type="checkbox"], input[type="radio"]').on('ifChanged', function (e) {
$(this).trigger("onclick", e);
});