javascript 使用 iCheck-helper 时如何处理无线电事件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25562062/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 04:40:32  来源:igfitidea点击:

How to handle radio event when iCheck-helper is used?

javascriptjquerycss

提问by KiranD

I want to handle the radio button on change event. But, as the designer has already used iCheck-helper, the actual radio actions are not performed when the code is run.

我想处理更改事件的单选按钮。但是,由于设计人员已经使用了 iCheck-helper,因此在运行代码时不会执行实际的无线电操作。

Below is the code

下面是代码

<div class="radio-wrap">
   <input type="radio" id="bg-effect" value="full" />Full Image
</div>

When we run the code and inspect the code in chrome, the generated HTML is as below.

当我们运行代码并在 chrome 中检查代码时,生成的 HTML 如下所示。

<div class="radio-wrap">
  <div class="iradio_minimal-grey checked"><input type="radio" id="bg-effect" value="full" checked="" style="position: absolute; opacity: 0;"><ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);"></ins></div>Full Image
</div>

To capture the selected value, I want to handle the change event for this radio button.

为了捕获选定的值,我想处理此单选按钮的更改事件。

回答by Ilya Luzyanin

According to documentation, you can use ifChangedevent like this:

根据文档,您可以使用这样的ifChanged事件:

$('#bg-effect').on('ifChanged', function(event){
    alert(event.type + ' callback');
});

回答by Ansy

I ran throught the same problem,later i found useful fix as has been correctly answered from github forum : read from this thread

我遇到了同样的问题,后来我找到了有用的修复程序,因为已从 github 论坛正确回答: 阅读此线程

The following was a fix:

以下是一个修复:

$('input').on('ifCreated ifClicked ifChanged ifChecked ifUnchecked ifDisabled ifEnabled ifDestroyed check ', function(event){                
                    if(event.type ==="ifChecked"){
                        $(this).trigger('click');  
                        $('input').iCheck('update');
                    }
                    if(event.type ==="ifUnchecked"){
                        $(this).trigger('click');  
                        $('input').iCheck('update');
                    }       
                    if(event.type ==="ifDisabled"){
                        console.log($(this).attr('id')+'dis');  
                        $('input').iCheck('update');
                    }                                
                }).iCheck({
                    checkboxClass: 'icheckbox_minimal-green',
                    radioClass: 'iradio_minimal-green'
                        //increaseArea: '20%'
                });