Check/Uncheck - ifChecked not working

独自空忆成欢 提交于 2019-12-06 12:19:53

Try:

on page load:

 alert($('input').is(':checked'));

http://jsfiddle.net/9ypwjvt4/18/

else use:

   $(document).ready(function () {
    $('input').iCheck({
        checkboxClass: 'icheckbox_square-orange',
        radioClass: 'iradio_square-orange',
        increaseArea: '20%' // optional
    });

    $('input').on('ifChecked', function(event){
      alert('Checked');
    });

    $('input').on('ifUnchecked', function(event){
      alert('unchecked');
    });
});

jsfiddle: http://jsfiddle.net/9ypwjvt4/17/

Use on change event instead on using ifChecked or ifUnchecked

$('input.icheck').on('change', function (event) {
    if ($("input#CreatePart").is(':checked')) {
        alert('checked');
    }else{
       alert("unchecked");
    }

});

Change your condition on ifUnchecked to make sure the checkbox is NOT checked instead of checked.

You were checking to see if the box is checked when the unchecked event is fired which that would never happen.

$('input').on('ifUnchecked', function (event) {
    if ($("input#CreatePart").not(':checked')) {
        alert('un-checked');
    }
});

DEMO:

http://jsfiddle.net/ejLbgt7b/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!