13

基本单选框

<div class="adv_filter">
    <li>
        <input type="radio" name="letter_type" data-custom="Text" value="0"> Text</li>
    </li>
        <li>
            <input type="radio" name="letter_type" data-custom="Text" value="0"> Text</li>
    </li>
</div>

iCheck 转换

<!-- iCheck output format
<div class="adv_filter">
    <li>
        <div class="iradio_square-orange checked" aria-checked="true" aria-disabled="false" style="position: relative;"><input type="radio" name="letter_type" data-custom="Text" value="0" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);"><ins class="iCheck-helper" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);"></ins></div> Text</li>

        <li>
            <div class="iradio_square-orange" aria-checked="false" aria-disabled="false" style="position: relative;"><input type="radio" name="letter_type" data-custom="Text" value="0" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);"><ins class="iCheck-helper" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);"></ins></div> Text</li>

</div> -->

如您所见,已选中已附加到 div..

    $(document).ready(function () {
        $('input').iCheck({
            checkboxClass: 'icheckbox_square-orange',
            radioClass: 'iradio_square-orange',
            increaseArea: '20%' // optional
        });
        $("li").on("click", "input", function () {
            var val = $(this).val();
            //updateDataGrid(val);
            alert(val);
        });

    });

问题和描述

如果在添加 icheck 插件之前 javascript 代码可以正常工作, 我想知道如何在 icheck 插件中获得相同的结果。它很简单,在无线电单击时它将值存储在变量中,稍后将其进一步传递给函数。

现场示例:http: //jsfiddle.net/9ypwjvt4/

iCheck:http ://fronteed.com/iCheck/

4

4 回答 4

25

将处理程序附加到ifChanged事件:

$('input').on('ifChecked', function(event){
  alert($(this).val()); // alert value
});

11 种方法可以监听变化

  • ifClicked- 用户单击自定义输入或分配的标签
  • ifChanged- 输入的检查、禁用或不确定状态已更改
  • ifChecked- 输入的状态更改为选中
  • ifUnchecked- 检查状态被删除
  • ifToggled- 输入的检查状态已更改
  • ifDisabled-输入的状态更改为禁用
  • ifEnabled- 禁用状态被移除
  • ifIndeterminate- 输入的状态更改为不确定
  • ifDeterminate- 不确定状态被移除
  • ifCreatedinput- 只是定制的
  • ifDestroyed- 自定义刚刚删除

JSFIDDLE

于 2014-10-18T16:17:02.527 回答
6

尽可能避免使用 jquery。您也可以使用下面的代码;

$('input').on('ifChecked', function(event){
    alert(event.target.value); // alert value
});
于 2015-07-20T12:00:58.833 回答
0

用这个

// Check #x
$( "#x" ).prop( "checked", true );
 
// Uncheck #x
$( "#x" ).prop( "checked", false );

于 2016-06-22T20:02:52.123 回答
-1
$('body').on('ifChecked','.icheck', function(){
//considering icheck is the class of your checkbox and it is getting generated dynamically
});
于 2016-07-21T10:40:45.433 回答