【问题标题】:Bootstrap ICheck can not listen changed eventBootstrap ICheck 无法监听更改的事件
【发布时间】:2020-12-16 01:22:00
【问题描述】:

我有这个 jQuery 代码根据是否检查了收音机来更新收音机。但是,这不会触发。

代码

    this.init = function() {
    $.ajax({
        "url": "/cms/api/task_management/init",
        "contentType": "application/json",
        "dataType": "json",
        "type": "POST"
    }).done(function(map) {
        if ($("#title").val() || $("#problemCls").val() || $("#targetFunc").val() || $("#status").val() || $("#priority").val()) {
            search();
        } else {
            callBackInit(map);
        }
    }).fail(failCallback);
    $("input[type='radio']").on("ifChanged", function (event) {
        if ($("#display-method-unique").prop("checked")) {
            renderDataTable(self.taskManagementList);
        } else {
            renderDataTable(self.allDataList);
        }
    }).iCheck({
        radioClass: 'iradio_flat-green'
    });

HTML

<div class="row">
     <div class="col-md-4 col-sm-12 col-xs-12">
          <div class="radio">
               <input type="radio" name="display-method" id="display-method-unique" class="flat"><label for="display-method-unique">Doing</label>
               <input type="radio" name="display-method" id="display-method-all" class="flat"><label for="display-method-all">End</label>
           </div>
    </div>
</div>

我也尝试过绑定到 click 函数和 change 函数。但是无法监听更改事件。然而,两者似乎都不起作用。当我不添加 Icheck.js 脚本时,一切正常。

有人知道如何从引导程序 Icheckhelper 类中挂钩更改的事件吗?

【问题讨论】:

标签: javascript jquery twitter-bootstrap icheck


【解决方案1】:

我发现了有用的修复,已从 github 论坛正确回答:read from this threadHow to handle radio event when iCheck-helper is used?

然后我更改了我的代码。问题已经解决了。

$("input[name='display-method']").iCheck({radioClass: 'iradio_flat-green'});

this.init = function() {
    $.ajax({
        "url": "/cms/api/task_management/init",
        "contentType": "application/json",
        "dataType": "json",
        "type": "POST"
    }).done(function(map) {
        if ($("#title").val() || $("#problemCls").val() || $("#targetFunc").val() || $("#status").val() || $("#priority").val()) {
            search();
        } else {
            callBackInit(map);
        }
        $("input[name='display-method']").on("ifCreated ifClicked ifChanged ifChecked ifUnchecked ifDisabled ifEnabled ifDestroyed check", function (event) {
            if ($("#display-method-unique").prop("checked")) {
                renderDataTable(self.taskManagementList);
            } else {
                renderDataTable(self.allDataList);
            }
        });
    }).fail(failCallback);
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多